C# webservices 之发布调用【3】

C# webservices 之自定义编写发布【2】

接着上篇自定义编写的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=\&quot;Web\&quot; /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即实体类。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值