2013-05-02 67 views
0

我的简单wcf运行正常,因为当我尝试创建一个应用程序给wcf时,它会返回所需的数据,但是当我试图在wcf服务之外运行应用程序运行,它给错误当试图在wcf服务运行以外的地方访问它时,无法访问wcf服务

enter image description here

我怎样才能解决这个问题?

WCF服务的web配置

<?xml version="1.0"?> 
     <configuration> 

      <system.web> 
      <compilation debug="true" targetFramework="4.0" /> 
      </system.web> 
      <system.serviceModel> 
<services> 
     <service name="WcfService1.Service1"> 
     <endpoint address="http://192.168.21.102:4424/Service1.svc" 
        binding="wsHttpBinding" 
        contract="WcfService1.IService1"></endpoint> 
     <endpoint address="mex" 
        binding="mexHttpBinding" 
        contract="IMetadataExchange"></endpoint> 
     </service> 
    </services> 
      <behaviors> 
       <serviceBehaviors> 
       <behavior> 
        <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --> 
        <serviceMetadata httpGetEnabled="true"/> 
        <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --> 
        <serviceDebug includeExceptionDetailInFaults="false"/> 
       </behavior> 
       </serviceBehaviors> 
      </behaviors> 
      <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 
      </system.serviceModel> 
     <system.webServer> 
      <modules runAllManagedModulesForAllRequests="true"/> 
      </system.webServer> 

     </configuration> 

客户端应用程序配置

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <system.serviceModel> 
     <bindings> 
      <basicHttpBinding> 
       <binding name="BasicHttpBinding_IService1" 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:4424/Service1.svc" binding="basicHttpBinding" 
       bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference1.IService1" 
       name="BasicHttpBinding_IService1" /> 
     </client> 
    </system.serviceModel> 
</configuration> 

我DIDM \不能触摸或编辑那些东西

+0

你有WCF配置的应用程序的app.config? – Hyralex 2013-05-02 03:09:10

+0

@Hyralex,我没有,只是一个webconfig – SHINHAN 2013-05-02 03:09:59

+0

@SHINHAN - 你能澄清你的意思是'WCF外的应用程序吗?您是否尝试运行该服务而不托管它?或试图通过客户端从另一台计算机连接到它? – Tim 2013-05-02 04:05:26

回答

0

两件事情:

首先,你的服务定义为使用wsHttpBinding,但您的客户使用的是basicHttpBinding。绑定需要匹配。

其次,客户端配置中的地址设置为localhost - 这意味着您的客户端正在客户端所在的同一台计算机上查找服务。例如,如果您的服务位于名为MySever1的计算机上(例如),并且您将客户端(使用发布的配置)放在名为MyClient1的计算机上(例如,再次),则会查找MyClient1上的服务(客户端的本地主机)。

将客户端端点更改为http://192.168.21.102:4424/Service1.svc,并且应该能够连接,禁止任何防火墙问题。

例如:

<client> 
    <endpoint address="http://192.168.21.102:4424/Service1.svc" 
      binding="basicHttpBinding" 
      bindingConfiguration="BasicHttpBinding_IService1" 
      contract="ServiceReference1.IService1" 
      name="BasicHttpBinding_IService1" /> 
</client> 

编辑

在服务端配置,执行端点如下:

service name="WcfService1.Service1"> 
    <endpoint address="" 
       binding="basicHttpBinding" 
       contract="WcfService1.IService1"> 
    </endpoint> 
    <endpoint address="mex" 
       binding="mexHttpBinding" 
       contract="IMetadataExchange"> 
    </endpoint> 
    </service> 

在您的客户端配置:

<client> 
    <endpoint address="http://192.168.21.102:4424/Service1.svc" 
      binding="basicHttpBinding" 
      bindingConfiguration="BasicHttpBinding_IService1" 
      contract="ServiceReference1.IService1" 
      name="BasicHttpBinding_IService1" /> 
</client> 

请注意,在服务端点声明中,address属性为空 - 使用* .svc文件的位置来确定实际地址。其次,将绑定更改为basicHttpBinding以匹配客户端将调用的内容。

在客户端配置中,指定您要呼叫的服务的完整地址。

+0

但是,当我尝试重建wcf解决方案并在浏览器中查看它给我错误“当'system.serviceModel/serviceHostingEnvironment/multipleSiteBindingsEnabled'是在配置中设置为true时,端点需要指定一个相对地址,如果你在端点上指定了一个相对的listen URI,那么地址可以是绝对的,为了解决这个问题,指定一个相对uri作为端点http:/ /192.168.21.102:4424/Service1.svc'。 – SHINHAN 2013-05-02 04:57:06

+0

请参考我的编辑方法来解决这个问题 – Tim 2013-05-02 05:08:07

+0

我已经试过了,客户端给出了错误信息“没有端点监听http://192.168.21.102: 4424/Service1.svc可以接受该消息。这通常是由不正确的地址或SOAP操作引起的。请参阅InnerException(如果存在)以获取更多详细信息“ – SHINHAN 2013-05-02 05:13:47