簡體   English   中英

在Windows Phone Mango中啟用WCF呼叫

[英]Enable WCF calls in a Windows Phone Mango

我根據本教程在托管Windows服務中開發了WCF。

這是我的界面的定義方式:

namespace HomeAutomationWindowsService
{
    [ServiceContract]
    public interface IHomeAutomation
    {
        [OperationContract]
        string connect();

        [OperationContract]
        Boolean sendAction(string address, string command);
    }
}

我的App.config文件是這樣的:

<?xml version="1.0"?>
<configuration>

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="Unsecured">
          <security mode="None" />
        </binding>
      </wsHttpBinding>
    </bindings>
    <services>
      <service name="HomeAutomationWindowsService.HomeAutomationService"
               behaviorConfiguration="HomeAutomationServiceBehavior">
      <host>
          <baseAddresses>
              <add baseAddress="http://192.168.11.178:8000/service"/>
          </baseAddresses>
      </host>
        <!-- this endpoint is exposed at the base address provided by     host: http://localhost:8000/service  -->
        <endpoint address=""
                  contract="HomeAutomationWindowsService.IHomeAutomation"
                  binding="wsHttpBinding"
                  bindingConfiguration="Unsecured" />
        <!-- the mex endpoint is explosed at http://192.168.11.178:8000/    mex -->
        <endpoint address="mex"
                  binding="mexHttpBinding"
                  contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="HomeAutomationServiceBehavior">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="False"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

當我從控制台或WPF應用程序撥打電話時,可以看到公用方法,但是當我使用Windows Phone進行呼叫時,看不到任何東西。

如何使WCF或Windows Phone一起通信。

我認為WP7不支持WsHttpBinding 嘗試使用BasicHttpBinding

Web.config:

  <system.serviceModel>
    <services>
      <service name="MyProject.MyService" behaviorConfiguration="behavior">
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="binding" contract="MyProject.MyService" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="behavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <basicHttpBinding>
        <binding name="binding">
        </binding>
      </basicHttpBinding>
    </bindings>
  </system.serviceModel>

將Web服務添加到WP7項目(添加服務參考)后, ServiceReferences.ClientConfig看起來應該像(使用WsHttpBinding添加Web服務WsHttpBinding生成一個空文件):

<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_DataService" maxBufferSize="2147483647"
                    maxReceivedMessageSize="2147483647">
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="https://localhost:44300/Services/DataService.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_DataService"
                contract="DataService.DataService" name="BasicHttpBinding_DataService" />
        </client>
    </system.serviceModel>
</configuration>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM