2012-08-08 27 views
0

我有一个未公开的Web服务,我需要使用用Visual C#编写的客户端来获取此Web服务的版本。问题是我太过于菜鸟。试图使C#客户端与本地主机上的Web服务通信

我在Visual Studio中添加了服务引用,所以我得到了一个代理文件和output.config文件。

我从VS此行启动类的新实例:

DentalScannerServiceClient client = new DentalScannerServiceClient(); 

所以我把这个在我的控制台应用程序:

DentalScannerServiceClient client = new DentalScannerServiceClient(); 
client.GetSoftwareVersion(); 

得到错误“,没有超载的方法'GetSoftwareVersion'接受0个参数“。 Intelisens告诉我这当我开始输入client.GetSoftwareVersion:

状态DentalScannerServiceClient.GetSoftwareVersion(出字符串版本

所以我试试这个代码:

DentalScannerServiceClient client = new DentalScannerServiceClient(); 
    string oo; 
    client.GetSoftwareVersion(out oo); 

,然后打印字符串但是当我运行代码时出现此错误:

“InvalidOperationException is unhandled” “无法在ServiceModel客户端配置部分中找到引用合同'IDentalScannerService'的默认端点元素。这可能是因为没有找到适用于您的应用程序的配置文件,或者因为在客户端元素中找不到匹配此合同的端点元素。 ?

任何想法如何解决这个问题或者从哪里开始寻找我感谢所有帮助也许这是一些简单用C#我一点经验以及

的app.config:。

<?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用,只是做了项目 - >添加现有项添加它:

<?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> 
+1

您是否在dll中编写代码?如果是这样,您需要将配置复制到应用程序配置文件。 – 2012-08-08 14:39:50

+0

你可以发布你的配置文件吗? – retslig 2012-08-08 19:28:52

+0

我在一个基本的Program.cs,控制台应用程序中编写代码。 – 2012-08-09 07:34:16

回答

0

因为我无法得到这种方法工作,我做到了另一种方式:

  1. 使用WSDL所产生的.wsdl文件。exe文件在SDK
  2. 下载的soapUI,并开始一个新的项目与WSDL文件作为初始文件
  3. 的soapUI创造了所有的Web服务
  4. 测试在soapUI的不同调用对象的SOAP请求并得到响应住
  5. 推门进去,C#VS,使我的控制台应用程序第一次启动Web服务,然后使用HttpWebRequest的发送简单的SOAP请求
  6. 宾果

这种方法的效果非常好!

0

这很可能是由于端点不止一次出现在您的配置文件中。找到部分<system.serviceModel><client></client></system.serviceModel>并检查重复项(基于名称)

如果客户端部分不存在于您的配置文件中,您将需要添加它。 按照这个模板

<configuration> 
    <system.serviceModel> 
     <client> 
      <endpoint address="<address here>" binding="basicHttpBinding" contract="<full qualifeid class name to client interface>" name="<some name here>" /> 
     </client> 
    </system.serviceModel> 
</configuration> 
+0

那么,我有两个配置文件。 app.config和output.config。那是问题吗? (在两个客户端标记) – 2012-08-09 07:35:28

+0

唯一一个重要的是他app.config为可执行文件或web.config为您的网站运行 – iamkrillin 2012-08-09 13:08:10

相关问题