【问题标题】:access local self-hosted WCF service from asp.net Website从 asp.net 网站访问本地自托管 WCF 服务
【发布时间】:2014-09-18 16:19:00
【问题描述】:

我有一个在 Windows 窗体应用程序中托管的 WCF 服务库。我想从托管在 azure 网站上的 asp.net 网站调用该服务。我在网站项目中创建了一个服务引用,并尝试从后面的代码中调用一些服务功能。 当我这样做时,我收到以下错误:

  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

我的服务正在运行,我可以在浏览器中访问服务地址。 是否可以从网站调用服务?

编辑:

我的服务配置:

<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:

 <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>

【问题讨论】:

  • 您正在尝试从 Azure 连接到 localhost?这似乎是Azure Service Bus 的候选人

标签: c# asp.net wcf azure


【解决方案1】:

为了建立您描述的架构,您应该查看 Azure 服务总线,它“允许您在现有(本地)环境中托管 WCF 服务,并通过在 Azure 中运行的服务总线将请求委托给这些 WCF 服务。”

以下 Microsoft Azure 链接概述了您的方案:

服务总线中继服务使您能够构建在 Azure 数据中心和您自己的本地企业环境中运行的混合应用程序。服务总线中继通过使您能够将驻留在公司企业网络中的 Windows Communication Foundation (WCF) 服务安全地公开给公共云来促进这一点,而无需打开防火墙连接或需要对公司网络基础结构进行侵入性更改。

http://azure.microsoft.com/en-us/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

【讨论】:

    猜你喜欢
    • 2016-04-18
    • 2011-06-30
    • 1970-01-01
    • 2010-09-22
    • 2023-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多