在C#中的Web服务的WSDL文件使用主机名的困惑 [英] Confused by use of host name in WSDL file in C# Web Service

查看:479
本文介绍了在C#中的Web服务的WSDL文件使用主机名的困惑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了C#部署在Windows服务EXE一个WCF Web服务这在很大程度上是工作,我想要的方式。我使用它在自托管的方式(而不是在IIS)。

I have created a WCF web service in C# deployed in a Windows Service EXE which is largely working the way I want. I am using it in a self-hosted manner (not within IIS).

为了使可用于调用Java的web服务的WSDL文件,我添加的ServiceMetadataBehavior到举办创造。即:

In order to make a WSDL file available to the calling Java webservice, I added ServiceMetadataBehavior to the host creation. i.e:

ServiceHost host = new ServiceHost(typeof(MyService));
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
host.Description.Behaviors.Add(smb);
host.Open();

这一切工作正常,直到我搬到我的服务到另一台服务器使用不同的主机名。当我连接到WSDL(HTTP:// PROD-服务器:55000 /为MyService WSDL),我看到开发服务器的主机名在WSDL是硬编码。

This all worked fine until I moved my service to another server with a different host name. When I connect to the WSDL (http://prod-server:55000/MyService?wsdl), I see that the host name of the development server is hard coded in the WSDL.

下面是看到在浏览器中WSDL的一个片段:

Here is a snippet of the WSDL as seen in a browser:

<wsdl:definitions name="MyService" targetNamespace="http://tempuri.org/">
<wsdl:import namespace="MyProject.ServiceContracts" location="http://dev-server:55000/MyService?wsdl=wsdl0"/>
<wsdl:types/>



我已经检查所有的C#代码的项目,以及开发服务器名称不硬编码。随时随地

I have checked all of the C# code in the project, and the development server name is not hard coded anywhere.

在App.config文件中,我有以下定义:

In the App.config file, I have the following defined:

<system.serviceModel>
<services>
  <service name="MyService">
    <endpoint address="http://localhost:55000/MyService" binding="basicHttpBinding"
      bindingConfiguration="" contract="MyProject.ServiceContracts.IMyInterface" />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:55000/MyService" />
      </baseAddresses>
    </host>
  </service>
</services>



我希望这会导致本地主机的机器名称被取代,但它仍然存在作为该服务最初创建/部署的发展框名称。难道我错了?

I would expect that this would result in the localhost machine name being substituted, but it persists as the development box name on which the service was originally created / deployed. Am I mistaken?

我也看了成明确指明了我的WSDL文件的路径的可能性,但是从我可以推断,这只能如果托管完成服务上的IIS。

I also looked into the possibility of explicitly specifying a path to my WSDL file, but from what I can deduce, this can only be done if hosting the service on IIS.

最后一点,纯粹出于好奇,我想知道或者实际被创建的实际WSDL文件(磁盘上的物理文件,我的意思)是动态呈现在每个请求?

Lastly and purely out of curiosity, I wonder if an actual WSDL file actually gets created (a physical file on disk I mean) or is it dynamically rendered with each request?

推荐答案

这是动态创建的,不是每一个电话IIRC,但在第一次请求的元数据终结点。我不知道为什么你非DEV机上看到您的DEV服务器名,但是,因为你只在你的端点地址localhost指定它会使用主网络地址,为服务器解析DNS。您可能需要考虑增加 useRequestHeadersForMetadataAddress 行为,你的配置,以便与该服务被访问,而不是实际使用的DNS。

It is created dynamically, not every call IIRC, but on first request to the metadata endpoint. I'm not sure why your seeing your DEV server name on the non-DEV machine, but, because you're specifying localhost only in your endpoint address it's going to resolve DNS using the primary network address for the server. You may want to consider adding the useRequestHeadersForMetadataAddress behavior to your config so that the DNS with which the service is accessed is actually used instead.

这篇关于在C#中的Web服务的WSDL文件使用主机名的困惑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆