简单的 WCF 服务在不同机器上部署后未被调用,但在我的本地系统上运行良好

Simple WCF service not getting called after deploying on different machine, however works fine on my local system

我刚刚尝试创建一个非常简单的 wcf 应用程序。那是点击按钮我试图在页面上打印 "Hello World" 。我发布了该服务,它再次在我的本地系统上运行良好,但同样当我尝试在服务器上部署时却没有。这个应用程序非常简单,没有复杂性,没有数据库连接,什么都没有。但是仍然无法从服务器调用服务。检查服务,(Service1.svc -。右键单击 -> 浏览) 工作正常,但为什么它无法通过应用程序调用,我不知道。它现在变得更加混乱了。对此完全一窍不通。发布代码中使用的所有 3 个必要文件。

web.config 文件:

<?xml version="1.0"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
    <system.web>
        <compilation debug="true" targetFramework="4.0" />
    </system.web>
    <system.serviceModel>
<services>
        <service name ="ApplicationReturnString.Web.Service1.svc">
          <endpoint address="" binding="basicHttpBinding"
                contract="ServiceReference1.IService1"/>
        </service>
      </services> 
        <behaviors>
            <serviceBehaviors>
                <behavior name="">
                    <serviceMetadata httpGetEnabled="true" />
                    <serviceDebug includeExceptionDetailInFaults="false" />
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    </system.serviceModel>
</configuration>

ClientAccessPolicy.xml 文件:

<?xml version="1.0" encoding="utf-8" ?>
<access-policy>
  <cross-domain-access>
    <policy>
      <allow-from http-request-headers="*">
        <domain uri="*"/>
      </allow-from>
      <grant-to>
        <resource include-subpaths="true" path="/"/>
      </grant-to>
    </policy>
  </cross-domain-access>
</access-policy>

CrossDomain.xml 文件:

<?xml version="1.0" ?>
<!DOCTYPE cross-domain-policy SYSTEM 
    "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
  <allow-http-request-headers-from domain="*" headers="*"/>
</cross-domain-policy>

ServiceRefrence.ClientConfig 文件:

<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IService1" maxBufferSize="2147483647"
                    maxReceivedMessageSize="2147483647">
                    <security mode="None" />
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:52731/Service1.svc" binding="basicHttpBinding"
                bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference1.IService1"
                name="BasicHttpBinding_IService1" />
        </client>
    </system.serviceModel>
</configuration>

谢谢 Roy 和 Nitin。实际上,问题在于在 web.config 文件中设置端点地址,并且随着服务部署到其他机器上,应用程序的 URL 也发生了变化。所以我做了下面给出的一些重要更改: 1. 在 web.config 文件中提供与 ServiceRefrence.ClientConfig 文件中相同的端点地址、端点名称和合同详细信息。 2. 更改 ServiceRefrence.ClientConfig 中没有特定端口详细信息的端点地址:;而不是 ; 和 3. 在应用程序中编码以获取执行它的机器的 URI 地址,这样无论应用程序部署在何处,用户都不必担心本地主机地址及其端口详细信息:Uri servUri = new Uri(". ./Service.svc", UriKind.Relative); EndpointAddress servAddr = new EndpointAddress(servUri); ServiceReferenceForSelect.ServiceForSelectClient objSelect = new ServiceForSelectClient("BasicHttpBinding_IService", servAddr);