接着上篇自定义编写的webservice,我们自己写个程序调用,就用之前第一篇天气预报的项目代码接着往里添加
将本机的 http://localhost:6060/myWebService.asmx 改成本机的IP地址 让局域网里面的同事访问一下先。
如果报 “测试窗体只能用于来自本地计算机的请求”或者"The test form is only available for requests from the local machine. ",
在web.config的<system.web></system.web>中间加入如下配置节内容
<webServices>
<protocols>
<add name="HttpSoap"/>
<add name="HttpPost"/>
<add name="HttpGet"/>
<add name="Documentation"/>
</protocols>
</webServices>
即可正常访问。
然后在右键-添加web引用
输入发布的地址,转到即可看到,我们自己发布的webservices方法,点击 添加引用
测试界面
后台代码
protected void btnS2_Click(object sender, EventArgs e)
{
WebReference.myWebService mw = new WebReference.myWebService();
string resultStr = mw.AcceptBrxxInsert("mm", "m", "2016-05-26 14:24:28", "27", "m", "m", "2000-05-26 14:25:43", "m");
lblR.Text = resultStr;
}
运行效果
到目前为止,调用自己发布的webservices已经可以成功访问了。
================================================
实体类类名参考web.config
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.6.1"/>
<httpRuntime targetFramework="4.6.1"/>
</system.web>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701"/>
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+"/>
</compilers>
</system.codedom>
<appSettings>
<add key="localhost.myWebService" value="http://localhost:9001/myWebService.asmx"/>
</appSettings>
</configuration>
localhost.myWebService mw = new localhost.myWebService();
string resultStr = mw.AcceptBrxxInsert("测试", "测试", "测试", "", "", "", "", "");
lblR.Text = resultStr;
<add key="localhost.myWebService" value="http://localhost:9001/myWebService.asmx"/>
key即实体类。