Excelの登録なしにWCFモニカーの「インターフェイスは見つかりません」

StackOverflow https://stackoverflow.com/questions/2968963

質問

ExcelをWCFサービスに接続しようとしていますが、些細なケースでさえ動作することはできません... Excelでプロキシを作成しようとすると無効な構文エラーが発生します。 Visual Studio Debuggerを添付してExcelを添付し、実際のエラーが「インターフェイスが見つかりません」と判断しました。 Visual Studioによって作成されたテストクライアントが大丈夫であるため、サービスが機能することはわかっています...そのため、問題はVBAモニカーの文字列にあります。

私は2つのことのいずれかを見つけたいと思っています:

1)この作業を行う私のモニカーの文字列への修正、または

2)機能するホストとクライアントの両方のソースを備えたダウンロードする既存のサンプルプロジェクト。

これが私のVBAクライアントのコードです:

Dim addr As String
addr = "service:mexAddress=net.tcp://localhost:7891/Test/WcfService1/Service1/mex, "
addr = addr + "address=net.tcp://localhost:7891/Test/WcfService1/Service1/, "
addr = addr + "contract=IService1, contractNamespace=http://tempuri.org, "
addr = addr + "binding=NetTcpBinding_IService1, bindingNamespace=""http://tempuri.org"""

MsgBox (addr)

Dim service1 As Object
Set service1 = GetObject(addr)

MsgBox service1.Test(12)

私は次のサービスを持っています:

[ServiceContract]
public interface IService1
{
    [OperationContract]
    string GetData(int value);
}

public class Service1 : IService1
{
    public string GetData(int value)
    {
        return string.Format("You entered: {0}", value);
    }
}

次の構成ファイルがあります。

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

  <system.web>
    <compilation debug="true" />
  </system.web>
  <!-- When deploying the service library project, the content of the config file must be added to the host's 
  app.config file. System.Configuration does not support config files for libraries. -->
  <system.serviceModel>
    <services>
      <service behaviorConfiguration="WcfService1.Service1Behavior"
        name="WcfService1.Service1">
        <endpoint address="" binding="netTcpBinding" bindingConfiguration=""
          contract="WcfService1.IService1">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
          contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://localhost:7891/Test/WcfService1/Service1/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="WcfService1.Service1Behavior">
          <serviceMetadata httpGetEnabled="false" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

</configuration>

編集:

私のために働いた更新されたモニカーは次のとおりでした

Dim addr As String
addr = "service:mexAddress=""net.tcp://localhost:7891/Test/WcfService1/Service1/Mex"", "
addr = addr + "address=""net.tcp://localhost:7891/Test/WcfService1/Service1/"", "
addr = addr + "contract=""IService1"", contractNamespace=""http://tempuri.org/"", "
addr = addr + "binding=""NetTcpBinding_IService1"", bindingNamespace=""http://tempuri.org/"""
役に立ちましたか?

解決 2

私はこれを修正することができました。モニカーの文字列のいくつかの重要な場所にいくつかの引用を追加することができました...残念ながら、デバッガーをExcelに添付すると、有用なフィードバックが少なくなります。 VBAでは、モニカの各文字列の周りに二重の引用( "")が必要です。さらに、MEXアドレスの「MEX」という用語は、契約のアドレスを小文字として指定したにもかかわらず、大文字にする必要があります。図に行く。

他のヒント

.NETオブジェクトとしてクライアントを作成し、comオブジェクトとして登録し、com経由でVBAからアクセスする予定です

更新:この記事を見つけました:http://msdn.microsoft.com/en-us/library/ms752245.aspx

モニカーを使用するには、クライアントを生成してからcomに登録してから、そのガイドをタイプとして使用する必要があるようです。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top