我有一个未记录的 Web 服务,我需要使用用 Visual C# 编写的客户端来获取此 Web 服务的版本。问题是我太菜鸟了。
我在 Visual Studio 中添加了服务引用,所以我得到了一个代理文件和 output.config 文件。
我从 VS 得到这一行来启动该类的新实例:
DentalScannerServiceClient client = new DentalScannerServiceClient();
所以我把它放在我的控制台应用程序中:
DentalScannerServiceClient client = new DentalScannerServiceClient();
client.GetSoftwareVersion();
收到错误“方法 'GetSoftwareVersion' 没有重载需要 0 个参数”。当我开始输入 client.GetSoftwareVersion 时,Intelisens 会告诉我这一点:
状态 DentalScannerServiceClient.GetSoftwareVersion(输出字符串版本)
所以我试试这段代码:
DentalScannerServiceClient client = new DentalScannerServiceClient();
string oo;
client.GetSoftwareVersion(out oo);
然后打印字符串,但是当我运行代码时出现此错误:
"InvalidOperationException 未处理" "在 ServiceModel 客户端配置部分中找不到引用合同 'IDentalScannerService' 的默认端点元素。这可能是因为找不到您的应用程序的配置文件,或者因为找不到与此合同匹配的端点元素客户元素。 ”
任何想法如何解决这个问题或从哪里开始寻找?我很感谢任何帮助。也许这很简单。我对 C# 的经验也很少。
应用程序配置:
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="ThisIsTest.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
</sectionGroup>
</configSections>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup><applicationSettings>
<ThisIsTest.Properties.Settings>
<setting name="ThisIsTest_localhost_DentalScannerService" serializeAs="String">
<value>http://localhost:8731/DentalServiceLib/DentalScannerService/</value>
</setting>
</ThisIsTest.Properties.Settings>
</applicationSettings>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicEndPoint" 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>
</bindings>
<client>
<endpoint address="http://localhost:8731/DentalServiceLib/DentalScannerService/"
binding="basicHttpBinding" bindingConfiguration="BasicEndPoint"
contract="Scanner.IDentalScannerService" name="BasicEndPoint" />
</client>
</system.serviceModel>
</configuration>
output.config(从 wsdl.exe 得到这个,只是做了 Project->Add Existing Item来添加它:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicEndPoint" 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>
</bindings>
<client>
<endpoint address="http://localhost:8731/DentalServiceLib/DentalScannerService/"
binding="basicHttpBinding" bindingConfiguration="BasicEndPoint"
contract="IDentalScannerService" name="BasicEndPoint" />
</client>
</system.serviceModel>
</configuration>