我正在尝试将 .asmx Web 服务合并到我的应用程序中。
为此,我 1. 创建了一个类库项目。2. 使用给定的 wsdl 添加服务引用 3. 自动创建了一个 app.Config。app.config 是
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="UploadWebServiceSoap" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
<customBinding>
<binding name="UploadWebServiceSoap12">
<textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
messageVersion="Soap12" writeEncoding="utf-8">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</textMessageEncoding>
<httpTransport manualAddressing="false" maxBufferPoolSize="524288"
maxReceivedMessageSize="65536" allowCookies="false" authenticationScheme="Anonymous"
bypassProxyOnLocal="false" decompressionEnabled="true" hostNameComparisonMode="StrongWildcard"
keepAliveEnabled="true" maxBufferSize="65536" proxyAuthenticationScheme="Anonymous"
realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false"
useDefaultWebProxy="true" />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="http://localhost:xxxx/xxx/UploadWebService.asmx"
binding="basicHttpBinding" bindingConfiguration="UploadWebServiceSoap"
contract="ServiceReference1.UploadWebServiceSoap" name="UploadWebServiceSoap" />
<endpoint address="http://localhost:xxxx/xxx/UploadWebService.asmx"
binding="customBinding" bindingConfiguration="UploadWebServiceSoap12"
contract="ServiceReference1.UploadWebServiceSoap" name="UploadWebServiceSoap12" />
</client>
</system.serviceModel>
完成所有设置后,我尝试在我的函数中调用 web-service 中的方法。
UploadWebServiceSoapClient dpcClient = new UploadWebServiceSoapClient();
这是出错的地方
Could not find default endpoint element that references contract 'ServiceReference1.UploadWebServiceSoap' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.
谁能告诉我为什么我会收到这个错误。此外,我了解创建 basicHttpBinding 的绑定,但是创建了相同的端点和端点