4

これに従って、asp.net 3.5 で json Web サービスを作成しました。

.NET 3.5 での JSON 対応 WCF サービスの作成 (archive.org)

(以前: http://www.pluralsight.com/community/blogs/fritz/archive/2008/01/31/50121.aspx )

内部で使用したい場合は問題なく動作しますが、外部に接続したいので、「このサービスのメタデータ公開は現在無効になっています」というエラーが表示されました。

そのため、有効にしようとしましたが、「基になる動作タイプが IEndpointBehavior インターフェイスを実装していないため、'serviceMetadata' 動作拡張を 'MyServiceAspNetAjaxBehavior' エンドポイント動作に追加できません。」というエラーが表示されます。

私は web.config で何か間違ったことをしていることを知っていますが、それを理解できません。何が間違っているのでしょうか? ありがとう!

これは web.config にあります。

<system.serviceModel>
<behaviors>
  <endpointBehaviors>
    <behavior name="MyServiceAspNetAjaxBehavior">
      <enableWebScript />
      <serviceMetadata httpGetEnabled="true" />
    </behavior>
  </endpointBehaviors>
</behaviors>

//Needed to add this to be able to use the web service on my shared host
<serviceHostingEnvironment aspNetCompatibilityEnabled="true">
  <baseAddressPrefixFilters>
    <add prefix="http://www.domain.com"/>
  </baseAddressPrefixFilters>
</serviceHostingEnvironment>

<services>
  <service name="MyService">
    <endpoint address="" behaviorConfiguration="MyServiceAspNetAjaxBehavior" binding="webHttpBinding" contract="MyService" />
    <endpoint contract="MyService" binding="mexHttpBinding" address="mex" />

  </service>
</services>

MyService.cs で:

using System;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;

[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class MyService
{
    [OperationContract]

    public string GetForecast(string str)
    {
        return "Hello World";
    }
}

MyService.svc 内

<%@ ServiceHost Language="C#" Debug="true" Service="MyService" CodeBehind="~/App_Code/MyService.cs" %>
4

2 に答える 2

1

MEX エンドポイント (メタデータ交換用のエンドポイント) には、特定のシステム指定のコントラクトIMetadataExchange(構成で間違っている) が必要です。

<services>
  <service name="MyService">
    <endpoint 
        address="" 
        behaviorConfiguration="MyServiceAspNetAjaxBehavior" 
        binding="webHttpBinding"   
        contract="MyService" />
    <endpoint 
        address="mex"
        binding="mexHttpBinding" 
        contract="IMetadataExchange"   />
  </service>
</services>

そのコントラクトでは、メタデータを表示できるはずです。

ただし、警告の言葉: RESTful サービスは通常、WSDL や XSD などのメタデータを公開しません。これは実際には SOAP の概念です。

マルク

于 2009-09-19T13:48:31.473 に答える