none
Calling WCF from VBA through Metadata Exchange Contract RRS feed

  • Question

  • Hi Friends,

    I have created the WCF service and was able to call that services from VBA through Metadata exchange contract with the help of below snippet. The reason why it is working is because [OperationContract]  double Multiply(double n1, double n2);  has primitive data type (int,string, double etc) as return type and argument. But If i have any complex type (like class, Data contracts) as argument or return type it is failing.

    If not possible, Can some one show me the msdn link saying that it is not possible to use WCF moniker call  involving data contracts ?

    http://msdn.microsoft.com/en-us/library/ms752245.aspx

    ' Create a string for the service moniker specifying the address to retrieve the service metadata from
    mexMonikerString = "service4:mexAddress='http://localhost/servicemodelsamples/service.svc/mex'"
    mexMonikerString = mexMonikerString + ", address='http://localhost/ServiceModelSamples/service.svc'"
    mexMonikerString = mexMonikerString + ", binding=WSHttpBinding_ICalculator, bindingNamespace='http://Microsoft.ServiceModel.Samples'"
    mexMonikerString = mexMonikerString + ", contract=ICalculator, contractNamespace='http://Microsoft.ServiceModel.Samples'"
    ' Create the service moniker object
    Set mexServiceMoniker = GetObject(mexMonikerString)
    WScript.Echo "MEX service moniker: 9 * 81.25 = " & mexServiceMoniker.Multiply(9, 81.25)

    Error it throws is : "Type load exception". Can somebody help me? Thanks


    Thanks


    Thursday, July 4, 2013 9:11 AM

All replies

  • Hi, what do you mean with "use WCF moniker call  involving data contracts ", can you give an example?

    Check a thread hope it helps.

    http://stackoverflow.com/questions/12745115/calling-wcf-webservice-from-excel-vba-using-getobject-method

    Friday, July 5, 2013 6:27 AM
  • Hi Nico,

    For ex if I have Data contracts of class. For instance, In the below example you can see that my operational contract involves complex type like data class object.

    You can refer my question to check how i am using moniker string from VBA. Please let me know if you have any question.

     [OperationContract]
        void SubmitData(Data data);

    [DataContract]
    public class Data
    {
        [DataMember]
       
    public int Id;
        [DataMember]
       
    public DateTime LockTime;
        [DataMember]
       
    public DateTime LoginTime;
        [DataMember]
       
    public DateTime LastDefenitionDate;
        [DataMember]
       
    public string NTLogin;
        [DataMember]
       
    public string SystemName;
    }


    Thanks

    Friday, July 5, 2013 9:14 AM
  • Hi Nandakumar,

    For WCF service that uses complex class, you might consider using the "Typed Contract" approach mentioned in the MSDN reference. That way, the standard .NET service proxy and data contract types are exposed to VBA application via COM interfaces. But, the drawback is that the client need to explicitly register the wrapped COM component before using the service.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, August 2, 2013 1:49 AM
    Moderator