对象不是从wcf web服务返回的
我已经在wcf中编写了一个返回对象的web服务。但当我从客户端代码调用它时,它不会返回任何对象 我要返回的对象是我的类对象不是从wcf web服务返回的,wcf,Wcf,我已经在wcf中编写了一个返回对象的web服务。但当我从客户端代码调用它时,它不会返回任何对象 我要返回的对象是我的类 [DataContract] public class OrderData { [DataMember] public List<ORDER_INFO> OrderInfoList { get; set; } [DataMember] public List<ORDER_PRODU
[DataContract]
public class OrderData
{
[DataMember]
public List<ORDER_INFO> OrderInfoList { get; set; }
[DataMember]
public List<ORDER_PRODUCT_MAPPING> OrderProductMappingList { get; set; }
}
My Service Interface
[ServiceContract]
public interface ISyncService
{
[OperationContract]
OrderData InsertOrderData(decimal depotId);
}
[DataContract]
公共类OrderData
{
[数据成员]
公共列表OrderInfoList{get;set;}
[数据成员]
公共列表OrderProductMappingList{get;set;}
}
我的服务接口
[服务合同]
公共接口ISyncService
{
[经营合同]
OrderData InsertOrderData(十进制depotId);
}
接口实现类
public class SyncService : ISyncService
{
readonly InceptaDbContext _db = new InceptaDbContext();
public OrderData InsertOrderData(decimal depotId)
{
var orderData = new OrderData
{
OrderInfoList = new List<ORDER_INFO>(),
OrderProductMappingList = new List<ORDER_PRODUCT_MAPPING>()
};
var orderList = _db.ORDER_INFO
.Where(m => m.D_ID.Equals(depotId)&& m.STATUS.Equals("1"));
//.Where(m => m.STATUS.Equals("1"));
foreach (var orderInfo in orderList)
{
orderData.OrderInfoList.Add(orderInfo);
orderData.OrderProductMappingList.AddRange(
_db.ORDER_PRODUCT_MAPPING.Where(m => m.ORDER_ID.Equals
(orderInfo.ORDER_ID)));
}
foreach (var orderInfo in orderList)
{
orderInfo.STATUS = "2";
_db.Entry(orderInfo).State = EntityState.Modified;
}
_db.SaveChanges();
return orderData;
}
}
公共类同步服务:ISyncService
{
只读InceptaDbContext _db=new InceptaDbContext();
public OrderData InsertOrderData(十进制depotId)
{
var orderData=新的orderData
{
OrderInfoList=新列表(),
OrderProductMappingList=新列表()
};
var orderList=\u db.ORDER\u INFO
其中(m=>m.D_ID.Equals(depotId)和&m.STATUS.Equals(“1”));
//其中(m=>m.STATUS.Equals(“1”));
foreach(orderList中的var orderInfo)
{
orderData.OrderInfoList.Add(orderInfo);
orderData.OrderProductMappingList.AddRange(
_db.ORDER\u PRODUCT\u映射,其中(m=>m.ORDER\u ID.Equals
(orderInfo.ORDER_ID));
}
foreach(orderList中的var orderInfo)
{
orderInfo.STATUS=“2”;
_db.Entry(orderInfo).State=EntityState.Modified;
}
_db.SaveChanges();
返回订单数据;
}
}
我的服务器web配置
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true" />
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<directoryBrowse enabled="true" />
</system.webServer>
<connectionStrings>
<add name="InceptaDbContext"
connectionString="metadata=res://*/DbContext.Model1.csdl|res://*/DbContext.Model1.ssdl|res://*/DbContext.Model1.msl;provider=Oracle.DataAccess.Client;provider connection string="DATA SOURCE=localhost/InceptaMSFA;PASSWORD=bs23;PERSIST SECURITY INFO=True;USER ID=BS"" providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
我的客户端应用程序是C中的控制台应用程序#
主程序
class Program
{
static void Main(string[] args)
{
var client = new SyncServiceClient();
var db = new InceptaDbContext();
var order = client.InsertOrderData(1.0m);
foreach (var s in order.OrderInfoList)
{
db.ORDER_INFO.Add(new ConsumeDataSyncService.DbContext.ORDER_INFO
{
ORDER_ID = s.ORDER_ID,
CH_ID = s.CH_ID,
D_ID = s.D_ID,
EMP_ID = s.EMP_ID,
ORDER_DATE = s.ORDER_DATE,
ORDER_TYPE = s.ORDER_TYPE,
PAY_OPTION = s.PAY_OPTION,
PRODUCT_COUNT = s.PRODUCT_COUNT,
STATUS = "2"
});
Console.WriteLine(s.ORDER_ID +"Inserted");
}
foreach (var s in order.OrderProductMappingList)
{
var orderProductMapping = new ConsumeDataSyncService.DbContext.ORDER_PRODUCT_MAPPING
{
ID = s.ID,
ORDER_ID = s.ORDER_ID,
P_CODE = s.P_CODE,
QUANTITY = s.QUANTITY
};
db.ORDER_PRODUCT_MAPPING.Add(orderProductMapping);
Console.WriteLine(s.ID + "Inserted");
}
db.SaveChanges();
Console.ReadKey();
}
}
and app.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ISyncService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8092/SyncService.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ISyncService" contract="OrderSyncService.ISyncService" name="BasicHttpBinding_ISyncService" />
</client>
</system.serviceModel>
<connectionStrings>
<add name="InceptaDbContext" connectionString="metadata=res://*/DbContext.Model1.csdl|res://*/DbContext.Model1.ssdl|res://*/DbContext.Model1.msl;provider=Oracle.DataAccess.Client;provider connection string="DATA SOURCE=192.168.1.159/Incepta;PASSWORD=bs23;USER ID=BS"" providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
the error I got at the time of debugging
Failed to invoke the service. Possible causes: The service is offline or inaccessible; the client-side configuration does not match the proxy; the existing proxy is invalid. Refer to the stack trace for more detail. You can try to recover by starting a new proxy, restoring to default configuration, or refreshing the service.
The underlying connection was closed: The connection was closed unexpectedly.
Server stack trace:
at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)
at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at ISyncService.InsertOrderData(Decimal depotId)
at SyncServiceClient.InsertOrderData(Decimal depotId)
Inner Exception:
The underlying connection was closed: The connection was closed unexpectedly.
at System.Net.HttpWebRequest.GetResponse()`enter code here`
at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
类程序
{
静态void Main(字符串[]参数)
{
var client=新的SyncServiceClient();
var db=新的InceptaDbContext();
风险值顺序=客户端插入数据(1.0m);
foreach(order.OrderInfoList中的变量s)
{
db.ORDER\u INFO.Add(新建ConsumerDataSyncService.DbContext.ORDER\u INFO
{
订单号=s.订单号,
CHU ID=s.CHU ID,
D_ID=s.D_ID,
EMP_ID=s.EMP_ID,
订单日期=美国订单日期,
订单类型=s.订单类型,
支付期权=s.支付期权,
产品计数=s.产品计数,
STATUS=“2”
});
控制台写入线(s.ORDER_ID+“插入”);
}
foreach(order.OrderProductMappingList中的变量s)
{
var orderProductMapping=new consumerdatasyncservice.DbContext.ORDER\u产品\u映射
{
ID=s.ID,
订单号=s.订单号,
P_代码=s.P_代码,
数量=s.数量
};
db.ORDER\u PRODUCT\u MAPPING.Add(orderProductMapping);
控制台写入线(s.ID+“插入”);
}
db.SaveChanges();
Console.ReadKey();
}
}
和app.config
调试时出现的错误
未能调用该服务。可能原因:服务离线或无法访问;客户端配置与代理不匹配;现有代理无效。有关更多详细信息,请参阅堆栈跟踪。您可以尝试通过启动新代理、恢复到默认配置或刷新服务来进行恢复。
基础连接已关闭:连接意外关闭。
服务器堆栈跟踪:
位于System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException WebException、HttpWebRequest请求、HttpBortreason abortReason)
位于System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan超时)
位于System.ServiceModel.Channels.RequestChannel.Request(消息消息,TimeSpan超时)
位于System.ServiceModel.Dispatcher.RequestChannelBinder.Request(消息消息,TimeSpan超时)
在System.ServiceModel.Channels.ServiceChannel.Call(字符串操作、布尔单向、ProxyOperationRuntime操作、对象[]输入、对象[]输出、时间跨度超时)
位于System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage方法调用,ProxyOperationRuntime操作)
位于System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage消息)
在[0]处重试异常:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg,IMessage retMsg)
at System.Runtime.Remoting.proxy.RealProxy.PrivateInvoke(MessageData&msgData,Int32类型)
在ISyncService.InsertOrderData(十进制depotId)上
在SyncServiceClient.InsertOrderData处(十进制depotId)
内部异常:
基础连接已关闭:连接意外关闭。
在System.Net.HttpWebRequest.GetResponse()中,在此处输入代码`
位于System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRe
[Serializable,DataContract()]