1

SilverLightコードからWCF関数を実行しようとしました。WCFはサイトwww.my-site.comで実行されています。Silverlightアプリケーションは、サイトwww.vkontakte.ruからダウンロードされるhtmlページの<IFrame/>部分としてサイトwww.my-site.comからダウンロードされます。a:ActionNotSupportedエラーを受け取りました。
なにが問題ですか?

これが私のSilverlightアプリケーションによって送信されたリクエストです。

POST http://www.my-site.com/MyService.svc HTTP / 1.1
Accept:/
Referer:http
://www.my-site.com/ClientBin/MySlApp.xap Accept-Language:ru-RU
Content-長さ:153
コンテンツタイプ:text / xml; charset = utf-8
SOAPAction: "http://tempuri.org/IMyService/Add"
Accept-Encoding:gzip、deflate
User-Agent:Mozilla / 5.0(互換性、MSIE 9.0、Windows NT 6.1、Trident / 5.0)
ホスト: www.my-site.com
接続:Keep-Alive
Pragma:キャッシュなし

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Body>
    <Add xmlns="http://tempuri.org/">
      <a1>1</a1>
      <a2>1</a2>
    </Add>
  </s:Body>
</s:Envelope>

その結果、私は次の応答を受け取りました:

HTTP / 1.1 500内部サーバーエラー
Cache-Control:private
Content-Length:710
Content-Type:application / xml; charset = utf-8
サーバー:Microsoft-IIS / 7.5
X-AspNet-バージョン:4.0.30319
X-Powered-By:ASP.NET
日付:2011年9月11日日曜日16:34:19 GMT

<Fault xmlns="http://schemas.microsoft.com/ws/2005/05/envelope/none">
  <Code>
    <Value>Sender</Value>
    <Subcode>
      <Value xmlns:a="http://schemas.microsoft.com/ws/2005/05/addressing/none">
        a:ActionNotSupported
      </Value>
    </Subcode>
  </Code>
  <Reason>
    <Text xml:lang="en-US">
      The message with Action '' cannot be processed at the receiver,
      due to a ContractFilter mismatch at the EndpointDispatcher.
      This may be because of either a contract mismatch
      (mismatched Actions between sender and receiver)
      or a binding/security mismatch between the sender and the receiver.
      Check that sender and receiver have the same contract and the same binding
      (including security requirements, e.g. Message, Transport, None).
    </Text>
  </Reason>
</Fault>

Silverlightリクエストコード:

        BasicHttpBinding basicHttpBinding = new BasicHttpBinding();
        EndpointAddress endpointAddress =
            new EndpointAddress("http://www.my-site.com/MyService.svc");
        IDbService service =
            new ChannelFactory<IDbService>(basicHttpBinding, endpointAddress)
                .CreateChannel();
        AsyncCallback asy = delegate(IAsyncResult result)
                                {
                                    Trace.WriteLine(service.EndAdd(result));
                                };
        service.BeginAdd(1, 1, asy, null);

Silverlight操作契約インターフェイス:

[ServiceContract]
public interface IMyService
{
    [OperationContract(AsyncPattern = true)]
    IAsyncResult BeginAdd(long a1, long a2, AsyncCallback callback, object state);

    long EndAdd(IAsyncResult result);
}

WCF操作契約インターフェース:

[ServiceContract]
public interface IMyService
{
    [OperationContract]
    long Add(long a1, long a2);
}

WCFサービスコード:

[AspNetCompatibilityRequirements(
    RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class MyService: IMyService
{
    public long Add(long a1, long a2)
    {
        return a1 + a2;
    }
}

web.configの一部:

<system.serviceModel>
  <behaviors>
    <serviceBehaviors>
      <behavior name="MySlApp.Web.ServiceMyServiceAspNetAjaxBehavior">
        <serviceMetadata httpGetEnabled="true"/>
        <serviceDebug includeExceptionDetailInFaults="true"/>
      </behavior>
    </serviceBehaviors>
    <endpointBehaviors>
      <behavior name="MySlApp.Web.MyServiceAspNetAjaxBehavior">
        <enableWebScript />
      </behavior>
    </endpointBehaviors>
  </behaviors>
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
      multipleSiteBindingsEnabled="true" />
  <services>
    <service name="MySlApp.Web.DbService"
             behaviorConfiguration="MySlApp.Web.ServiceMyServiceAspNetAjaxBehavior">
      <endpoint address=""
          binding="webHttpBinding" contract="MySlApp.Web.IMyService" />
    </service>
  </services>
</system.serviceModel>

clientaccesspolicy.xml:

<?xml version="1.0" encoding="utf-8" ?>
<access-policy>
  <cross-domain-access>
    <policy>
      <allow-from http-request-headers="*">
        <domain uri="http://www.my-site.com" />
        <domain uri="http://www.vkontakte.ru" />
        <domain uri="http://*.vkontakte.ru" />
        <domain uri="http://www.vk.com" />
        <domain uri="http://*.vk.com" />
      </allow-from>
      <grant-to>
        <resource path="/" include-subpaths="true"/>
      </grant-to>
    </policy>
  </cross-domain-access>
</access-policy>

crossdomain.xml:

<?xml version="1.0" encoding="utf-8" ?>
<cross-domain-policy>
  <allow-access-from domain="www.my-site.com" />
  <allow-access-from domain="www.vkontakte.ru" />
  <allow-access-from domain="*.vkontakte.ru" />
  <allow-access-from domain="www.vk.com" />
  <allow-access-from domain="*.vk.com" />
</cross-domain-policy>
4

1 に答える 1

1

これはクロスドメインの問題ではありません。basicHttpBinding問題は、サーバーエンドポイントがを使用しているときに、に準拠するリクエストを送信していることですwebHttpBinding。web.configを以下のように変更すると、機能するはずです。

<system.serviceModel>
  <behaviors>
    <serviceBehaviors>
      <behavior name="MySlApp.Web.ServiceMyServiceAspNetAjaxBehavior">
        <serviceMetadata httpGetEnabled="true"/>
        <serviceDebug includeExceptionDetailInFaults="true"/>
      </behavior>
    </serviceBehaviors>
  </behaviors>
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
      multipleSiteBindingsEnabled="true" />
  <services>
    <service name="MySlApp.Web.DbService"
             behaviorConfiguration="MySlApp.Web.ServiceMyServiceAspNetAjaxBehavior">
      <endpoint address=""
          binding="basicHttpBinding" contract="MySlApp.Web.IMyService" />
    </service>
  </services>
</system.serviceModel>

サービスを変更できない場合は、クライアントを変更する必要があります。webHttpBindingWCF WebHttpエンドポイントとも呼ばれるエンドポイント、または(「REST」という用語を多用している)WCF RESTエンドポイントは、WCFプログラミングモデル(クライアントクラスChannelFactory<T>など)を使用してSL経由で直接アクセスすることはできません。それは可能ですが( SLを介したREST / POXサービスの利用に関する投稿、およびSLを介したREST / JSONサービスの利用に関する投稿を参照)、それほど簡単なことではありません(ほとんどの人は、WebClientまたはなどの単純なクラスを使用HttpWebRequestしてこれらのサービスを利用します。

于 2011-09-12T13:48:34.820 に答える