如何绑定WCF服务的IP地址绑定、地址、WCF、IP

2023-09-03 03:08:11 作者:我丑故我知

我正在开发由IIS托管WCF服务,使用VSTS2008 + C#+。NET 3.5的。我发现当引用从客户端通过使用添加服务引用服务......,客户端必须能够解决机器名到IP地址,因为WSDL引用由计算机名某些模式文件。这里是WSDL文件的一部分的一个例子中,为了从客户端解析WSDL文件生成代理,我们必须能够解析机器名testmachine1相关的IP地址,

I am developing a WCF service hosted by IIS, using VSTS2008 + C# + .Net 3.5. I find when reference the service from a client by using Add Service Reference..., client has to be able to resolve the machine name to IP address, because WSDL reference some schema file by machine name. Here is an example of a part of WSDL file, in order to parse WSDL file from client side to generate proxy, we have to be able to resolve machine name testmachine1 to related IP address,

<xsd:import schemaLocation="http://testmachine1/service.svc?xsd=xsd1" 
     namespace="http://schemas.microsoft.com/2003/10/Serialization/"/>

我的问题是,由于某种原因机器名称不能被解析所有的时间(对于非技术原因),所以我想绑定到托管IIS服务器的IP地址。可能吗?如果是的话,AP preciate,如果有人可以提供意见。这是我目前的WCF的web.config文件,我想知道如何修改它,使之与IP地址的工作,

My question is, for some reason machine name cannot be resolved all the time (for non-technical reasons), so I want to bind to IP address of the hosting IIS server. Is it possible? If yes, appreciate if anyone could advise. Here is my current WCF web.config file, I want to know how to modify it to enable it to work with IP address,

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <services>
      <service behaviorConfiguration="Foo.WCF.ServiceBehavior"
        name="Foo.WCF.CustomerManagement">
        <endpoint address="" binding="basicHttpBinding" 
                  contract="Foo.WCF.ICustomerManagement">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" 
                  contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="Foo.WCF.ServiceBehavior">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

在此先感谢, 乔治

thanks in advance, George

推荐答案

如果您的WCF服务托管在IIS中,您不能设置一个独立的地址。您必须使用在您的SVC文件所居住的虚拟目录的URL - 无论是用机器名( HTTP://yourserver/virtualdir/myservice.svc )或IP(的http:// 123.123.123.123/virtualdir/myservice.svc )。

If your WCF service is hosted in IIS, you cannot set a separate address. You must use the URL of the virtual directory where your SVC file lives - either with a machine name (http://yourserver/virtualdir/myservice.svc) or an IP (http://123.123.123.123/virtualdir/myservice.svc).

如果您使用IP添加服务引用,该IP将在由服务导入生成的WSDL中使用。

If you use the IP to add the service reference, that IP will be used in the WSDL generated by the service import.

如果您在自己的WCF服务(Windows服务,控制台应用程序),你可以设置在配置服务地址,并使用机器名或IP的机器。

If you host the WCF service yourself (Windows service, console app), you can set the service address in config, and use either machine name or IP for the machine.

马克·