WCF und netTCPBinding

cipher

Grünschnabel
Hallo,

ich bin ebenfalls Neueinsteiger bei WCF Services und arbeite gerade an einer Übertragung eines .Net DataSets zwischen Client und Server.

Leider generiert mir das Tool svcutil.exe ein Interface, das nicht mit dem Interface auf der Serverseite übereinstimmt.

Hier ist das serverseitige Interface (Contract):

namespace WCFService
{
[ServiceContract]
public interface IWCFService
{
[OperationContract]
String returnEcho(String echo);

[OperationContract]
DataSet testDB();
}
}


Und hier die Implementierung:

namespace WCFService
{
public class WCFServiceType : IWCFService
{
public String returnEcho(String echo)
{
return echo;
}

public DataSet testDB()
{
return new Manager().getDataSet();
}
}
}


Der relevante Teil meiner App.config sieht so aus:
<system.serviceModel>
<services>
<service name="WCFService.WCFServiceType" behaviorConfiguration="WCFServiceTypeBehaviors">
<endpoint address="http://localhost:8000/myServer"
binding="basicHttpBinding"
contract="WCFService.IWCFService" />
<endpoint address="net.tcp://localhost:8010/myServer"
binding="netTcpBinding"
contract="WCFService.IWCFService" />
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:9999/myServer" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WCFServiceTypeBehaviors">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>


Wenn ich lediglich die returnEcho Methode als Service zur Verfügung stelle, funktioniert alles tadellos. Sobald ich jedoch den eigentlichen Service implementieren will (Übertragung eines DataSet-Objekts), bekomme ich Probleme.

Svcutil.exe generiert folgenden Code:

//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:2.0.50727.42
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System.Data;



[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(ConfigurationName="IWCFService")]
public interface IWCFService
{

// CODEGEN: Parameter 'returnEchoResult' requires additional schema information that cannot be captured using the parameter mode. The specific attribute is 'System.Xml.Serialization.XmlElementAttribute'.
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IWCFService/returnEcho", ReplyAction="http://tempuri.org/IWCFService/returnEchoResponse")]
[System.ServiceModel.XmlSerializerFormatAttribute()]
returnEchoResponse returnEcho(returnEchoRequest request);

// CODEGEN: Parameter 'testDBResult' requires additional schema information that cannot be captured using the parameter mode. The specific attribute is 'System.Xml.Serialization.XmlElementAttribute'.
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IWCFService/testDB", ReplyAction="http://tempuri.org/IWCFService/testDBResponse")]
[System.ServiceModel.XmlSerializerFormatAttribute()]
testDBResponse testDB(testDBRequest request);
}

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
[System.ServiceModel.MessageContractAttribute(WrapperName="returnEcho", WrapperNamespace="http://tempuri.org/", IsWrapped=true)]
public partial class returnEchoRequest
{

[System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://tempuri.org/", Order=0)]
[System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
public string echo;

public returnEchoRequest()
{
}

public returnEchoRequest(string echo)
{
this.echo = echo;
}
}

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
[System.ServiceModel.MessageContractAttribute(WrapperName="returnEchoResponse", WrapperNamespace="http://tempuri.org/", IsWrapped=true)]
public partial class returnEchoResponse
{

[System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://tempuri.org/", Order=0)]
[System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
public string returnEchoResult;

public returnEchoResponse()
{
}

public returnEchoResponse(string returnEchoResult)
{
this.returnEchoResult = returnEchoResult;
}
}

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
[System.ServiceModel.MessageContractAttribute(WrapperName="testDB", WrapperNamespace="http://tempuri.org/", IsWrapped=true)]
public partial class testDBRequest
{

public testDBRequest()
{
}
}

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
[System.ServiceModel.MessageContractAttribute(WrapperName="testDBResponse", WrapperNamespace="http://tempuri.org/", IsWrapped=true)]
public partial class testDBResponse
{

[System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://tempuri.org/", Order=0)]
[System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
public System.Data.DataSet testDBResult;

public testDBResponse()
{
}

public testDBResponse(System.Data.DataSet testDBResult)
{
this.testDBResult = testDBResult;
}
}

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
public interface IWCFServiceChannel : IWCFService, System.ServiceModel.IClientChannel
{
}

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
public partial class WCFServiceClient : System.ServiceModel.ClientBase<IWCFService>, IWCFService
{

public WCFServiceClient()
{
}

public WCFServiceClient(string endpointConfigurationName) :
base(endpointConfigurationName)
{
}

public WCFServiceClient(string endpointConfigurationName, string remoteAddress) :
base(endpointConfigurationName, remoteAddress)
{
}

public WCFServiceClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) :
base(endpointConfigurationName, remoteAddress)
{
}

public WCFServiceClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) :
base(binding, remoteAddress)
{
}

returnEchoResponse IWCFService.returnEcho(returnEchoRequest request)
{
return base.Channel.returnEcho(request);
}

public string returnEcho(string echo)
{
returnEchoRequest inValue = new returnEchoRequest();
inValue.echo = echo;
returnEchoResponse retVal = ((IWCFService)(this)).returnEcho(inValue);
return retVal.returnEchoResult;
}

testDBResponse IWCFService.testDB(testDBRequest request)
{
return base.Channel.testDB(request);
}

public System.Data.DataSet testDB()
{
testDBRequest inValue = new testDBRequest();
testDBResponse retVal = ((IWCFService)(this)).testDB(inValue);
return retVal.testDBResult;
}
}


Bei der Implementierung meines Clients taucht dann das Problem auf:
namespace WCFTestClient
{
static class WCFClient
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
//Application.EnableVisualStyles();
//Application.SetCompatibleTextRenderingDefault(false);
//Application.Run(new Form1());

IWCFService proxy = new ChannelFactory<IWCFService>().CreateChannel(NetTcpBinding_IWCFService);

DataSet testData = proxy.testDB();
}
}
}



Der Aufruf proxy.testDB() verlangt natürlich einen Parameter (Typ: testDBRequest). Kann mir jemand sagen wo hier die Fehler liegt ?
 

Neue Beiträge

Zurück