0

作成した簡単なWebサービスがあります。Visual Studio 2012.NET4.5を使用しています。

サービス契約は次のとおりです。

using System.Runtime.Serialization;
using System.ServiceModel;

namespace GEMS.Core.WCFService
{
    [ServiceContract]
    public interface IMenuService
    {
        [OperationContract]
        void AddMenuItem(string menuId, string parentId, string title, string description, string url);
        [OperationContract]
        void UpdateMenuItem(string menuId, string parentId, string title, string description, string url);
        [OperationContract]
        void DeleteMenuItem(string menuId);
        [OperationContract]
        MenuEntry[] GetAllMenuItems();
    }

    [DataContract]
    public class MenuEntry
    {
        [DataMember]
        public string MenuId { get; internal set; }
        [DataMember]
        public string ParentId { get; internal set; }
        [DataMember]
        public string Title { get; internal set; }
        [DataMember]
        public string Description { get; internal set; }
        [DataMember]
        public string Url { get; internal set; }
    }
}

app.configの関連部分は次のとおりです。

<system.serviceModel>
  <services>
    <service name="GEMS.Core.WCFService.MenuService">
      <host>
        <baseAddresses>
          <add baseAddress="http://localhost:8020/GEMS.Core.WCFService/MenuService/" />
        </baseAddresses>
      </host>
      <endpoint address="" binding="basicHttpBinding" contract="GEMS.Core.WCFService.IMenuService" >
        <identity>
          <dns value="localhost"/>
        </identity>
      </endpoint>
      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
    </service>
  </services>
  <behaviors>
    <serviceBehaviors>
      <behavior>
        <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
        <serviceDebug includeExceptionDetailInFaults="False" />
      </behavior>
    </serviceBehaviors>
  </behaviors>
</system.serviceModel>

IISサーバー(ボックスのローカル)に公開します。

クライアントアプリで、サービス参照を作成します。[検出]をクリックすると、次のように表示されます。

http://localhost:8020/GEMS.Core.WCFService/MenuService/mex

ただし、クライアントを実行すると、次のメッセージが表示されます。

There was no endpoint listening at:
http://localhost:8020/GEMS.Core.WCFService/MenuService/ that could
accept the message. This is often caused by an incorrect address or
SOAP action. See InnerException, if present, for more details.

内部例外は、Webサーバーから404エラーが発生したことを示しているだけです。

クライアントの.configファイルには、次の自動生成されたxmlがあります。

<system.serviceModel>
  <bindings>
    <basicHttpBinding>
      <binding name="BasicHttpBinding_IMenuService" />
    </basicHttpBinding>
  </bindings>
  <client>
    <endpoint address="http://localhost:8020/GEMS.Core.WCFService/MenuService/"
      binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMenuService"
      contract="WCF_MenuService.IMenuService" name="BasicHttpBinding_IMenuService" />
  </client>
 </system.serviceModel>

私は何時間も輪になって回っていて、何がグリッチになっているのか理解できませんが、確かに私は何か間違ったことをしました。

重要かどうかはわかりませんが、クライアントはASP.NETMVCアプリです。

4

1 に答える 1

1

ピートが説明したように、Newtonsoft.json.dllにより、クライアントはサービスコードを生成しません。dllを削除してから、サービス参照を再度追加することができます。

または、私のために働いた次の解決策を試すことができます。サービス参照を追加すると、

  1. [サービス参照の追加]ウィンドウの[詳細...]ボタンをクリックします
  2. 「参照されるアセンブリのタイプを再利用する」を無効にします。

次に、クラスを生成する必要があります。

于 2012-10-16T18:39:58.183 に答える