。net8调用webservice函数
1. nuget中加两个引用,注意:一定是要4.10.3这个版本,最新的10版本不行
<PackageReference Include="System.ServiceModel.Http" Version="4.10.3" />
<PackageReference Include="System.ServiceModel.Primitives" Version="4.10.3" />
2. 生成包装类,注意所指定的namespace,指令生成一个Reference.cs文件
dotnet tool install --global dotnet-svcutil dotnet-svcutil http://your-service.asmx?wsdl --namespace "*,YourNamespace.ServiceReference"
3. 把Reference.cs文件加入到工程中,即可调用service中的函数,若服务器url有变化可直接修改Reference.cs中的内容
net8调用webservice.ServiceReference2.WebService1SoapClient c = new net8调用webservice. ServiceReference2.WebService1SoapClient(net8调用webservice.ServiceReference2.WebService1SoapClient.EndpointConfiguration.WebService1Soap12);
byte[] buf = System.Text.UTF8Encoding.UTF8.GetBytes("abca中楞");
var t = await c.HelloWorld2Async("abc在", buf);
this.textBox1.Text = t.Body.HelloWorld2Result;
浙公网安备 33010602011771号