简体   繁体   中英

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. I would like to call that service from an asp.net website that is hosted on azure website. 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:

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

The following Microsoft Azure link provides an overview of your scenario:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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