简体   繁体   English

从asp.net网站访问本地自托管WCF服务

[英]access local self-hosted WCF service from asp.net Website

I have a WCF service library that I'm hosting in a Windows Forms application. 我有一个Windows窗体应用程序中托管的WCF服务库。 I would like to call that service from an asp.net website that is hosted on azure website. 我想从azure网站上托管的asp.net网站调用该服务。 I created a service reference at the website project and tried to call some of the service functions from code behind. 我在网站项目中创建了一个服务引用,并尝试从后面的代码中调用某些服务功能。 When I do so I get the following error: 当我这样做时,出现以下错误:

  An attempt was made to access a socket in a way forbidden by its access permissions 127.0.0.1:8732
    [SocketException (0x271d): An attempt was made to access a socket in a way forbidden by its access permissions 127.0.0.1:8732]
       System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) +208
       System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception) +464

    [WebException: Unable to connect to the remote server]
       System.Net.HttpWebRequest.GetRequestStream(TransportContext& context) +6543605
       System.Net.HttpWebRequest.GetRequestStream() +13
       System.ServiceModel.Channels.WebRequestHttpOutput.GetOutputStream() +55

    [EndpointNotFoundException: There was no endpoint listening at http://localhost:8732/Design_Time_Addresses/WcfServiceLibrary/ConnectService/ that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.]
       System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +10818447
       System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) +336
       TestProject.ConnectServiceReference.IConnectService.SayHello() +0

My service is running and I can access the service address in my browser. 我的服务正在运行,我可以在浏览器中访问服务地址。 Is it possible to call the service from the website? 是否可以从网站致电服务?

EDIT: 编辑:

My service config: 我的服务配置:

<system.serviceModel>
<serviceHostingEnvironment  multipleSiteBindingsEnabled="true" />
<services>
  <service behaviorConfiguration="MyServiceTypeBehaviors" name="WcfServiceLibrary.ConnectService">
    <endpoint address=""
      binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IConnectService" name="ServiceEndpoint" contract="WcfServiceLibrary.IConnectService">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" name="MetaDataEndpoint" contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8732/Design_Time_Addresses/WcfServiceLibrary/ConnectService/" />
      </baseAddresses>
    </host>
  </service>
</services>
<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_IConnectService"/>                 
  </basicHttpBinding>     
</bindings>    
 <behaviors>
 <serviceBehaviors>
    <behavior name="MyServiceTypeBehaviors" >
     <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
       <serviceDebug includeExceptionDetailInFaults="False" />
     </behavior>
  </serviceBehaviors>
</behaviors>
</system.serviceModel>

asp.net web.config: asp.net web.config:

 <bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_IConnectService">
      <security mode="TransportCredentialOnly">
        <transport clientCredentialType="None" proxyCredentialType="Windows" />
      </security>
    </binding>
  </basicHttpBinding>
  </bindings>
<client>     
  <endpoint address="http://localhost:8732/Design_Time_Addresses/WcfServiceLibrary/ConnectService/" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IConnectService"
    contract="ConnectServiceReference.IConnectService" name="BasicHttpBinding_IConnectService" />
</client>

In order to establish the architecture you described, you should look into the Azure Service Bus, which "allows you to host WCF services within your existing (local) environment and delegate requests to these WCF services via the Service Bus running within Azure." 为了建立您描述的体系结构,您应该查看Azure服务总线,它“允许您在现有(本地)环境中托管WCF服务,并通过在Azure中运行的服务总线将请求委派给这些WCF服务。”

The following Microsoft Azure link provides an overview of your scenario: 以下Microsoft Azure链接概述了您的方案:

The Service Bus Relay service enables you to build hybrid applications that run in both an Azure datacenter and your own on-premises enterprise environment. Service Bus Relay服务使您可以构建在Azure数据中心和您自己的本地企业环境中运行的混合应用程序。 The Service Bus relay facilitates this by enabling you to securely expose Windows Communication Foundation (WCF) services that reside within a corporate enterprise network to the public cloud, without having to open up a firewall connection or requiring intrusive changes to a corporate network infrastructure. Service Bus中继使您能够安全地将企业网络中的Windows Communication Foundation(WCF)服务公开到公共云,而不必打开防火墙连接或对企业网络基础结构进行侵入性更改,从而简化了此过程。

http://azure.microsoft.com/en-us/documentation/articles/service-bus-dotnet-how-to-use-relay/ http://azure.microsoft.com/zh-CN/documentation/articles/service-bus-dotnet-how-to-use-relay/

http://blogs.technet.com/b/meamcs/archive/2011/12/23/my-hello-azure-service-bus-wcf-service-step-by-step-guide.aspx http://blogs.technet.com/b/meamcs/archive/2011/12/23/my-hello-azure-service-bus-wcf-service-step-by-step-guide.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM