2009-11-08 81 views
1

像标题所说的那样,我们需要在.NET应用程序和Adobe AIR应用程序之间设置WCF服务。我们不想在机器上运行IIS,而更愿意安装和运行Windows服务中托管的WCF服务。当不在IIS中承载时通过HTTP公开WCF服务

但是,我不确定这样做会让我们使用HTTP作为传输,这只能在IIS内工作吗?我能够设置一些东西来使用TCP传输,但这与AIR的互操作性几乎和使用HTTP一样好。

编辑:

常规控制台应用程序:

static void Main() 
    { 
     using (ServiceHost host = new ServiceHost(typeof(TestService))) 
     { 
      host.Open(); 
     } 

     Console.WriteLine("Waiting..."); 
     Console.ReadLine(); 
    } 

TestService的是一个简单的HelloWorld类服务,我一直使用的是看这个作品的一些测试代码。

在App.config:

<configuration> 
    <system.serviceModel> 
    <services> 
     <service name="WCFExample2.TestService" behaviorConfiguration="WCFExample2.TestServiceBehavior"> 
     <host> 
      <baseAddresses> 
      <add baseAddress = "http://localhost:8731/Design_Time_Addresses/WCFExample2/Service1/" /> 
      </baseAddresses> 
     </host> 
     <!-- Service Endpoints --> 
     <!-- Unless fully qualified, address is relative to base address supplied above --> 
     <endpoint address ="" binding="wsHttpBinding" contract="WCFExample2.ITestService"> 
      <!-- 
       Upon deployment, the following identity element should be removed or replaced to reflect the 
       identity under which the deployed service runs. If removed, WCF will infer an appropriate identity 
       automatically. 
      --> 
      <identity> 
      <dns value="localhost"/> 
      </identity> 
     </endpoint> 
     <!-- Metadata Endpoints --> 
     <!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. --> 
     <!-- This endpoint does not use a secure binding and should be secured or removed before deployment --> 
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="WCFExample2.TestServiceBehavior"> 
      <!-- 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> 
    </system.serviceModel> 
</configuration> 
+0

好吧,在这里使用您的默认配置(没有任何''部分),您将使用wsHttpBinding(SOAP 1.2),并且您将使用基于消息的安全性,期望Windows用户凭证进行身份验证。这可能不是一个非常好的选择(取决于你的具体设置) – 2009-11-08 20:28:52

回答

1

除了配置文件设置还有一件事要考虑。 如果你在一个窗口服务,HTTP端点selfhost然后

  • 使服务的登录帐户本地管理员的机器 或
  • 您有HTTP.SYS注册为HTTP命名空间的服务帐户上。 这一步必须由本地管理员完成,但每台机器只能执行一次。您可以使用HttpSysCfg工具在XP/win 2003中执行此操作。对于vista/win 2008,请使用netsh。
3

你应该没有问题,设置Windows NT服务它承载WCF服务,并公开HTTP端点 - 无需IIS(但WCF运行时将使用http.sys内核模式驱动程序)。

您是否尝试过并失败?如果是这样 - 你能告诉我们你有什么,以及它失败的方式和方式?

作为最低限度,你可能希望有这样的配置在你的服务端:

<system.serviceModel> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="Default"> 
      <serviceMetadata httpGetEnabled="true"/> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <bindings> 
     <basicHttpBinding> 
     <binding name="Default" 
       sendTimeout="00:05:00" 
       maxBufferSize="500000" 
       maxReceivedMessageSize="500000" > 
      <security mode="Message"> 
      <message clientCredentialType="UserName" /> 
      </security> 
     </binding> 
     </basicHttpBinding> 
    </bindings> 
    <services> 
     <service name="Namespace.MyWCFService" 
       behaviorConfiguration="Default"> 
     <host> 
      <baseAddresses> 
      <add baseAddress="http://MyServer:8282/MyWCFService/"/> 
      </baseAddresses> 
     </host> 
     <endpoint 
      address="basic" 
      binding="basicHttpBinding" bindingConfiguration="Default" 
      contract="Namespace.IMyWCFService" /> 
     </service> 
    </services> 
    </system.serviceModel> 

当然,你可能需要调整的东西,如超时设置,缓冲区的大小设置等。在你的绑定,安全模式,以及很可能的其他设置,你需要他们。

马克

+0

它似乎工作,但浏览到端点给我一个“无法连接到这个网站”的错误,而不是拉动服务信息。 – FlySwat 2009-11-08 20:22:16

+0

那么,“真正的”端点是不可见的,并且可以通过浏览来访问 - 毕竟这是一条SOAP消息。使用Visual Studio“Common7/IDE”文件夹中的** WcfTestClient **应用程序 - 这非常适合测试。为了甚至可以看到WSDL(元数据),您需要在我的更新回复中发布的behaviorConfiguration。 – 2009-11-08 20:25:34

+0

您是否尝试启动wsdl页面 http:// MyServer:8282/MyWCFService /?wsdl – softveda 2009-11-08 22:47:10

2

你可以跳过所有的配置和使用WebServiceHost类(会做这一切为你在一个相当标准的方式)。得到这个工作,然后看看手动定制配置,以满足您可能有的任何额外要求。 所有你需要的信息在这里WebServiceHost on MSDN这是一个非常简单的开始使用自定义(即非IIS)托管http服务的方式。

Mike

+1

但这有点不同 - 使用WebServiceHost,您正在使用WCF通常使用的REST和SOAP。这可能(或可能不)是一个好主意 - 取决于情景。 – 2009-11-08 21:10:12

相关问题