Webservicekald
HejsaJeg har lavet to nøjagtig ens webservices, som ligger to forskellige steder. Men mærkeligt nok er det kun den ene som bliver kaldt.
Jeg har desuden forsøgt at ændre namespacet på den ene af dem uden held.
Er det god eller dårlig programmeringskik at have flere webservices? Eller skal man nøjes med en webservice til hele web-projektet?
Og hvorfor virker det ikke med den ene af de to jeg har lavet?
1) - som IKKE virker
Stinavn:
ServicePath= "~/Intranet/WebServiceServiceBulletin.asmx"
using System;
using System.Data;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Collections.Generic;
using System.ComponentModel;
namespace ServicePartner.Website.Intranet
{
/// <summary>
/// Summary description for WebServiceServiceBulletin
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
public class WebServiceServiceBulletin : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
public List<string> getPartlist(string prefixtext, short selected)
{
ServicePartner.Logic.Parts2 parts = new ServicePartner.Logic.Parts2();
List<string> list = parts.getPartlist(prefixtext, selected);
parts = null;
return list;
}
[WebMethod]
// SelectVariable 2: Partnumber
public string[] GetPartnumberList(string prefixText, int count)
{
if (count == 0)
{
count = 10;
}
List<string> items = new List<string>(count);
items = getPartlist(prefixText, 2);
items.Sort();
return items.ToArray();
}
// SelectVariable 3: Partname
[WebMethod]
public string[] GetPartNameList(string prefixText, int count)
{
if (count == 0)
{
count = 10;
}
List<string> items = new List<string>(count);
items = getPartlist(prefixText, 3);
items.Sort();
return items.ToArray();
}
}
}
og nr. 2 - som virker
Stinavn:
ServicePath="~/Admin/SPpartners/WebServiceParts.asmx"
using System;
using System.Data;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Collections.Generic;
using System.ComponentModel;
namespace ServicePartner.Website.Admin.SPpartners
{
/// <summary>
/// Summary description for WebServiceParts
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
[ToolboxItem(false)]
public class WebServiceParts : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
[WebMethod]
// SelectVariable 2: Partnumber
public string[] GetPartnumberList(string prefixText, int count)
{
if (count == 0)
{
count = 10;
}
List<string> items = new List<string>(count);
items = getPartlist(prefixText, 2);
items.Sort();
return items.ToArray();
}
// SelectVariable 3: Partname
[WebMethod]
public string[] GetPartNameList(string prefixText, int count)
{
if (count == 0)
{
count = 10;
}
List<string> items = new List<string>(count);
items = getPartlist(prefixText, 3);
items.Sort();
return items.ToArray();
}
public List<string> getPartlist(string prefixtext, short selected)
{
ServicePartner.Logic.Parts2 parts = new ServicePartner.Logic.Parts2();
List<string> list = parts.getPartlist(prefixtext,selected);
parts = null;
return list;
}
}
}
Her er aspx-filen, hvor ServicePath kun virker for
ServicePath="~/Admin/SPpartners/WebServiceParts.asmx"
<%@ Register TagPrefix="uc1" TagName="SectionMenu" Src="~/SectionMenu.ascx" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<%@ Page Language="C#" MasterPageFile="~/Intranet.Master" AutoEventWireup="false" Title="Servicebulletiner"
CodeBehind="ServiceBulletins.aspx.cs" Inherits="ServicePartner.Website.Intranet.ServiceBulletins" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<table id="Table1" height="90%" cellspacing="0" cellpadding="0" width="100%" border="0">
<tr>
<td width="190px">
<div class="TaskPad">
<uc1:SectionMenu ID="SectionMenu1" runat="server" ParentMenuID="3" />
</div>
</td>
<td valign="top" align="left">
<div class="Content">
<h1><asp:Label ID="LabelHeader" runat="server">Servicebulletiner</asp:Label></h1>
<div style="margin-left: 30px">
<div class="ContentAction">
<div style="margin-bottom:30px;">
Find servicebulletin
</div>
<table border="0">
<tr>
<td width="100px">
Søg efter ..
</td>
<td>
<asp:UpdatePanel ID="UpdatePanelTextBoxSearch" UpdateMode="Always" runat="server">
<ContentTemplate>
<asp:TextBox ID="TextBoxSearch" ToolTip="Søg på servicebulletiner" runat="server"
Width="250px" AutoPostBack="true" OnTextChanged="TextBoxSearch_TextChanged"></asp:TextBox>
<cc1:AutoCompleteExtender
ID="AutoCompleteExtenderService"
TargetControlID="TextBoxSearch"
ServicePath= "~/Intranet/WebServiceServiceBulletin.asmx"
ServiceMethod="GetPartNameList"
MinimumPrefixLength="2"
CompletionInterval="10"
EnableCaching="true"
CompletionSetCount="10"
runat="server">
</cc1:AutoCompleteExtender>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
</table>
</div>
</div>
</div>
</td>
</tr>
</table>
</asp:Content>