作为练习练习,我发布了一个(非常简单的)Web服务
http://www.myshoptour.com/WebServices/HelloWorldMST.asmx
测试页面运行良好,但我在网站上使用它时遇到了问题。我的代码如下:
RewriteRule ^([0-9]+)/?$ author.php?author_id=$1 [NC,L]
“新”这一行似乎是个问题。它什么都不做。好像它没有回来。我无法追查它。
有人可以告诉我我做错了什么(并告诉我正确的代码)吗?
提前致谢。对不起,如果这是错误的类别 - 自从我在这里发布以来已经有一段时间了。经过一段急需的休息后,我又回到了网络开发阶段!
编辑:
woodykiddy ...非常感谢你!我得到了它的工作。唯一的显着差异是:
最初: Dim wsProd As New wsHelloWorldMSTprod.HelloWorldMSTSoapClient()
修正: Dim wsProd As New wsHelloWorldMSTprod.HelloWorldMSTSoapClient(“HelloWorldMSTSo ap”)
再次感谢!
答案 0 :(得分:1)
这就是我在应用程序中使用Web服务的方法。我希望你会发现这个样本很有帮助。
我遵循的步骤
测试页面标记
<div>
Web Service Methods:
<asp:DropDownList runat="server" ID="DropDownList1" AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem Text="Please Select" Value=""></asp:ListItem>
<asp:ListItem Text="HelloWorld1" Value="1"></asp:ListItem>
<asp:ListItem Text="HelloWorld2" Value="2"></asp:ListItem>
</asp:DropDownList>
</div>
<div>
Web Service Response:
<br />
<asp:Label runat="server" ID="Label1" />
</div>
测试页面代码(C#)
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = "N/A";
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
using (var svc = new HelloWorldMSTSoapClient("HelloWorldMSTSoap"))
{
if(DropDownList1.SelectedValue == "1")
{
Label1.Text = svc.HelloWorld1();
}
else if (DropDownList1.SelectedValue == "2")
{
Label1.Text = svc.HelloWorld2();
}
else
{
Label1.Text = "N/A";
}
}
}
Web.config(服务模型部分) - 您不需要手动添加它,因为默认情况下由VS处理。
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="HelloWorldMSTSoap" />
</basicHttpBinding>
<customBinding>
<binding name="HelloWorldMSTSoap12">
<textMessageEncoding messageVersion="Soap12" />
<httpTransport />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="http://www.myshoptour.com/WebServices/HelloWorldMST.asmx"
binding="basicHttpBinding" bindingConfiguration="HelloWorldMSTSoap"
contract="HelloWorldMSTTest.HelloWorldMSTSoap" name="HelloWorldMSTSoap" />
<endpoint address="http://www.myshoptour.com/WebServices/HelloWorldMST.asmx"
binding="customBinding" bindingConfiguration="HelloWorldMSTSoap12"
contract="HelloWorldMSTTest.HelloWorldMSTSoap" name="HelloWorldMSTSoap12" />
</client>
</system.serviceModel>
<强>结果强>
选择HelloWorld1
时
选择HelloWorld2
时
注意强> 为方便起见,这里是后面代码的VB版本(由Telerik Code Converter转换)
Protected Sub Page_Load(sender As Object, e As EventArgs)
Label1.Text = "N/A"
End Sub
Protected Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs)
Using svc = New HelloWorldMSTSoapClient("HelloWorldMSTSoap")
If DropDownList1.SelectedValue = "1" Then
Label1.Text = svc.HelloWorld1()
ElseIf DropDownList1.SelectedValue = "2" Then
Label1.Text = svc.HelloWorld2()
Else
Label1.Text = "N/A"
End If
End Using
End Sub