我有一個簡單的自主主機WCF服務。我有這個服務在遠程服務器上運行。我能夠與我的機器上運行的客戶端進行通信以進行服務(我是本地管理員)。 但是,當我在不同的機器上運行相同的客戶端(非管理員),他們無法溝通。WCF客戶端無法在某些機器上連接
我監控資源管理器,我看到兩個隨機本地端口在每次服務調用時都打開並回撥。所以我無法打開特定的端口。
任何想法可能的原因或其他機器上的防火牆配置更改可能是什麼?
我對WCF很新。請原諒我,如果它的基本問題。
WCF服務器代碼
namespace CService
{
class Program
{
static void Main(string[] args) {
Console.Title = "C Service";
// Step 1 of the address configuration procedure: Create a URI to serve as the base address.
Uri baseAddress = new Uri("http://" + GetServerIPPort.ServerIP + ":" + GetServerIPPort.Port + "/CService/Service");
// Step 2 of the hosting procedure: Create ServiceHost
ServiceHost selfHost = new ServiceHost(typeof(CSerice), baseAddress);
try
{
// Step 3 of the hosting procedure: Add a service endpoint.
selfHost.AddServiceEndpoint(typeof(ICService), new BasicHttpBinding(), "CService");
// Step 4 of the hosting procedure: Enable metadata exchange.
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
selfHost.Description.Behaviors.Add(smb);
// Step 5 of the hosting procedure: Start (and then stop) the service.
selfHost.Open();
Console.WriteLine("The Coemet Service is ready and its listening on {0}", baseAddress.AbsoluteUri.ToString() + ":" + baseAddress.Port.ToString());
Console.WriteLine("Press <ENTER> to terminate service.");
Console.WriteLine();
Console.ReadLine();
// Close the ServiceHostBase to shutdown the service.
selfHost.Close();
}
catch (CommunicationException ce)
{
Console.WriteLine("An exception occurred: {0}", ce.ToString());
selfHost.Abort();
}
}
}
我有此鏈接http://msdn.microsoft.com/en-us/library/ms733133(v=vs.110).aspx
我的客戶代碼片段看起來是這樣的幫助generatedProxy對象。
string serviceEndPointAddress = "http://" + GetServerIPPort.ServerIP + ":" + GetServerIPPort.Port + "/CService/Service/CService";
var remoteAddress = new System.ServiceModel.EndpointAddress(new Uri(serviceEndPointAddress));
object rawOutput;
using (var client = new CServiceClient(new BasicHttpBinding(), remoteAddress))
{
client.Endpoint.Binding.SendTimeout = new TimeSpan(0, 0, 0, 100);
try
{
rawOutput = client.GetData(Identifier, field, date);
}
catch (Exception e)
{
errorMsg = e.ToString();
}
}\n
錯誤trowed在 「client.GetData(識別符,字段,日期)」
System.Runtime.Serialization.InvalidDataContractException:類型「System.Threading.Tasks.Task 1[System.Object]' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. If the type is a collection, consider marking it with the CollectionDataContractAttribute. See the Microsoft .NET Framework documentation for other supported types. at System.Runtime.Serialization.DataContract.DataContractCriticalHelper.ThrowInvalidDataContractException(String message, Type type) at System.Runtime.Serialization.DataContract.DataContractCriticalHelper.CreateDataContract(Int32 id, RuntimeTypeHandle typeHandle, Type type) at System.Runtime.Serialization.DataContract.DataContractCriticalHelper.GetDataContractSkipValidation(Int32 id, RuntimeTypeHandle typeHandle, Type type) at System.Runtime.Serialization.XsdDataContractExporter.GetSchemaTypeName(Type type) at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.CreatePartInfo(MessagePartDescription part, OperationFormatStyle style, DataContractSerializerOperationBehavior serializerFactory) at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.CreateMessageInfo(DataContractFormatAttribute dataContractFormatAttribute, MessageDescription messageDescription, DataContractSerializerOperationBehavior serializerFactory) at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter..ctor(OperationDescription description, DataContractFormatAttribute dataContractFormatAttribute, DataContractSerializerOperationBehavior serializerFactory) at System.ServiceModel.Description.DataContractSerializerOperationBehavior.GetFormatter(OperationDescription operation, Boolean& formatRequest, Boolean& formatReply, Boolean isProxy) at System.ServiceModel.Description.DataContractSerializerOperationBehavior.System.ServiceModel.Description.IOperationBehavior.ApplyClientBehavior(OperationDescription description, ClientOperation proxy) at System.ServiceModel.Description.DispatcherBuilder.BindOperations(ContractDescription contract, ClientRuntime proxy, DispatchRuntime dispatch) at System.ServiceModel.Description.DispatcherBuilder.BuildProxyBehavior(ServiceEndpoint serviceEndpoint, BindingParameterCollection& parameters) at System.ServiceModel.Channels.ServiceChannelFactory.BuildChannelFactory(ServiceEndpoint serviceEndpoint, Boolean useActiveAutoClose) at System.ServiceModel.ChannelFactory.CreateFactory() at System.ServiceModel.ChannelFactory.OnOpening() at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) at System.ServiceModel.ChannelFactory.EnsureOpened() at System.ServiceModel.ChannelFactory
1.CreateChannel(的EndpointAddress地址,烏里經由) 在System.ServiceModel.ClientBase 1.CreateChannel() at System.ServiceModel.ClientBase
1.CreateChannelInternal() 在System.ServiceModel.ClientBase`1.get_Channel() 在CServiceClient.GetData(字符串標識符,字符串字段中,日期時間日期)
問:你有什麼具體的錯誤?請發佈確切的錯誤消息(並在可能的情況下生成消息的相應代碼行)。 – FoggyDay
請分享CService的實現。該服務可能需要授權。 –
如果您還可以發佈您的ICService代碼,並且您的數據傳輸對象未在同一文件中定義,請發佈。 –