Tag: #wcf

无法找到WCF数据服务类型

我正在尝试将VSCF10中托管的WCF数据服务移动到开发Web服务器。 当我将代码移动到IIS7应用程序时,我收到此错误: 无法找到类型’Aaa.Bbb.Services.ZzzEntities’,作为ServiceHost指令中的Service属性值提供,或在配置元素system.serviceModel / serviceHostingEnvironment / serviceActivations中提供。 ZzzEntities.svc ZzzEntities.svc.cs using Aaa.Bbb.Domain.Entities; using System.Data.Services; using System.Data.Services.Common; using System.ServiceModel.Web; namespace Aaa.Bbb.Services { public class ZzzEntities:DataService { public static void InitializeService(DataServiceConfiguration config) { config.UseVerboseErrors = true; config.SetEntitySetAccessRule(“*”, EntitySetRights.All); config.SetServiceOperationAccessRule(“*”, ServiceOperationRights.All); config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3; } } } 编辑 :此外, Aaa.Bbb.Services.dll已编译并在IIS7 Web应用程序的\ bin目录中。 编辑 :按照这里的说明,我在尝试创建ZzzEntities实例时收到以下错误 – System.TypeLoadException:无法从程序集’Aaa.Bbb.Services,Version = 1.0.0.0,Culture = […]

使用带有WCF SOAP的XmlSerializer添加根xmlns

我有一个类文件,由我们的客户从第三方提供的XML Schema文档生成。 我应该能够将这个生成的类用于客户的SOAP Web服务,但是我遇到了一些问题。 我已经创建了一个ServiceContract接口,因此我可以使用WCF ChannelFactory连接到Web服务,如下所示: [ServiceContract(Namespace = “http://theircompany.co.uk/theirapp/v1”)] [XmlSerializerFormat] public interface IWebService { [OperationContract] EPSStatus serviceNotifyDataEventSet( [XmlElement(Namespace = “http://www.thirdparty.org/thirdapp”)] DataEventSet dataSet ); } EPSStatus和DataEventSet都在我生成的类文件中。 DataEventSet的重要部分: [System.CodeDom.Compiler.GeneratedCodeAttribute(“xsd”, “2.0.50727.42”)] [System.SerializableAttribute()] [System.Diagnostics.DebuggerStepThroughAttribute()] [System.ComponentModel.DesignerCategoryAttribute(“code”)] [System.Xml.Serialization.XmlTypeAttribute(Namespace=”http://www.thirdparty.org/thirdapp”)] [System.Xml.Serialization.XmlRootAttribute(Namespace=”http://www.thirdparty.org/thirdapp”, IsNullable=false)] public partial class DataEventSet { //… } 当我现在尝试调用IWebService.serviceNotifyDataEventSet我得到以下SOAP主体(在其服务器上启用了WCF跟踪): 47245361157 141728877218 2012-06-28T10:07:57.218+01:00 OSACBM_TIME_MIMOSA 42 0 SITE_SPECIFIC 141728877218 2012-06-28T10:07:57.218+01:00 OSACBM_TIME_MIMOSA 所以,我能够调用Web服务,看起来好像我的数据正确序列化,但是在服务器端, dataSet会出现空值。 我也从一个与以下机构合作的客户端得到了一个跟踪: […]

使用UserNameOverTransport绑定时,如何让WCF以摘要模式发送密码? (将WSE3.0代码转换为WCF)

我正在尝试将此WSE3.0代码转换为WCF: // we use Microsoft WSE 3.0 to insert the username token in the soap header. // This strategy takes care of creating and inserting the Nonce and Created elements // for us, as well as creating a password digest based on Nonce, Created, and // the password itself. Refer to the WS-Secutiry UsernameToken Profile […]

异步WCF方法等待后,WebOperationContext为null

在以下示例中,该方法作为WCF服务操作公开,并且该服务在IIS中承载。 在进入函数时,WebOperationContext.Current按预期设置。 然而,在await完成等待之后,WebOperationContext.Current被设置为null。 public async Task TestAsync() { //WebOperationContext.Current is set Task t = new Task(()=>Thread.Sleep(10000)); t.Start(); await t; //WebOperationContext.Current is null } 这似乎是一个缺点,所以我想知道是否有人知道这一点以及是否有任何好的方法。 我意识到我可以在局部变量中缓存对conext的引用,但这看起来不太好。 更新 一种有效的方法是 public async Task TestAsync() { WebOperationContext ctx = WebOperationContext.Current; Task t = new Task(()=>Thread.Sleep(10000)); t.Start(); await t; //ctx is set } 而且,正如其他人所暗示的那样,我可以做到这一点 public async Task TestAsync() { CallContext.LogicalSetData(“WebOperationContext.Current”, […]

如何使WCF RESTful服务工作异步?

我正在构建WCFrest服务,它是客户端。 我计划,客户端对服务知之甚少,只是正确的URL来调用方法和预期结果。 我的服务合同是: [WebInvoke(Method=”POST”, UriTemplate=”/tasks”)] [OperationContract] void SubmitTask(Transaction task); [WebGet(UriTemplate = “/tasks/{taskId}”)] [OperationContract] [XmlSerializerFormat] Transaction GetTask(string taskId); SubmitTask实现如下: SubmitTask(Transaction task) { DoSomethingWithTask(task); task.Status = “SomeStatus”; DoSomethingElseWithTaks(task); task.Status = “SomeOtherStatus”; } 我对客户的期望: ButtonClick() { SubmitTask(task); while(true) { string status = Transaction GetTask(task.taskId).Status; Textbox.Text+= status; if(status==ok) break; Thread.Sleep(1000); } } 问题是 – GetTask不在服务端执行,而所有SubmitTask操作都已完成,因此我只获得客户端的最后一个任务状态。 如何在这种情况下实现异步操作? 提前致谢!

WCF WebInvoke可以接受内容类型:text / plain?

我正在编写WCF REST服务以使用我的WCF REST服务接收AWS SNS通知消息。 但是,WCF REST仅支持XML和JSON,但由于传统原因,Amazon SNS使用Content-Type: text/plain; charset=UTF-8发布其通知Content-Type: text/plain; charset=UTF-8 根据亚马逊文档 , Content-Type: text/plain; charset=UTF-8标头: POST / HTTP/1.1 Content-Type: text/plain; charset=UTF-8 // … { “Type” : “Notification”, // … “UnsubscribeURL” : “https://sns.us-west-2.amazonaws.com/?Action=Unsubscribe&…” } 当我使用像Amazon这样的“text / plain”内容类型调用我的服务时,会出现一个错误: 请求错误。 服务器遇到处理请求的错误。 exception消息是’传入消息具有意外的消息格式’Raw’。 该操作的预期消息格式是’Xml’; ‘Json的’。 这可能是因为尚未在绑定上配置WebContentTypeMapper。 有关更多详细信息,请参阅WebContentTypeMapper的文档。 请参阅服务器日志以获取更多详 我目前的代码: public interface MyServiceInterface { [OperationContract] [WebInvoke(Method = “POST”, UriTemplate […]

如何在C#WCF中返回SqlDataReader?

在我的C#WCF服务中,我有一个SqlDataReader ,它包含我想要返回给客户端的数据行。 如何返回SqlDataReader所有内容? 现在我有 if (sqlReader != null) { if (sqlReader.HasRows) { while (sqlReader.Read()) { return sqlReader[0].ToString(); } sqlConn.Close(); } else { return null; } } 这只会返回第一个结果。 该类的返回类型目前是字符串。 我在想数组中的数组,但我不确定如何? 编辑: 感谢您的回复。 我有兴趣返回服务“创建”的整个SQL数据。 不在线第一列([0]) – 这仅用于测试。 但我不知道如何从服务回到客户端。 如何退货? 例如。 在Powershell中我会创建一个集合并向该集合添加对象,如果我必须在客户端之间传递它。 我在C#和WCF中寻找类似的东西。 非常感谢到目前为止:) 编辑#2: 得到它了! 🙂 创建了一个新类(例如): public class ObjectNotification { public string AlertDescription; public string Servername; […]

WCF – 想知道请求排队

我有一个关于WCF请求的简单问题。 当多个用户请求相同的进程时,WCF是否自动将请求排队到服务(该服务是单例),即假设我有一个需要一段时间才能完成的函数,并且两个用户调用此函数,WCF会自动执行对请求进行排队,以便在第一个请求完成后再开始处理下一个请求? 〜只是想知道

从WCF客户端连接到服务器的问题 – HTTPS端点 – 适用于本地开发但不适用于服务器

更新日志: 添加了更多详细信息 – 包括WCF跟踪。 首先,不是很多WCF经验,所以如果这是一个明显的错误,请道歉。 我正在编写一个简单的控制台应用程序,需要连接到第三方SOAP Web服务。 供应商提供的WSDL在这里: http://pastebin.com/LJurv0qA 我已经使用它在Visual Studio 2010(使用.NET 4.0)中创建服务引用来创建后面自动生成的代码。 我还为各种配置设置了app.config: <!—-> <!—-> 现在在我的LocalDevelopment框(即我的笔记本电脑)上,客户端工作正常,我可以使用他们的Logon()操作连接到第三方服务。 当我将我的代码部署到我们的测试服务器时,相同的代码和配置,n会引发以下exception: 日志文件已开始:18/11/2015 20:11:25在机器TESTSERVER上================================= =========================================== 18/11/2015 20: 11 >>>> ***已记录的应用程序:登录日期:18/11/2015 20:11:25消息:客户端问题(Client.Logon()) – 通信问题 – 消息:发出HTTP请求时发生错误to test.jsp。 这可能是由于在HTTPS情况下使用HTTP.SYS未正确配置服务器证书。 这也可能是由客户端和服务器之间的安全绑定不匹配引起的。 堆栈跟踪: 服务器堆栈跟踪:在System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException,HttpWebRequest request,HttpAbortReason abortReason) 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) System.ServiceModel.Channels.ServiceChannel.Call(String action,Boolean oneway,ProxyOperationRuntime operation,Object [] ins,Object [] outs,TimeSpan timeout)System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage […]

如何为没有SVC文件的自托管WCF服务指定ServiceHostFactory

我的应用程序作为Windows服务运行。 它使用以下帮助器方法动态创建WCF服务: public static void StartWebService(string webServiceName, Type serviceContractType, Type serviceImplementationType) { if (string.IsNullOrEmpty(webServiceName)) return; var baseAddress = GetWebServiceAddress(webServiceName); var baseUri = new Uri(baseAddress); lock (RunningWebServices) { if (RunningWebServices.ContainsKey(webServiceName)) return; var webServiceHost = new ServiceHost(serviceImplementationType, baseUri); var serviceBehaviour = new ServiceMetadataBehavior() { HttpGetEnabled = true }; webServiceHost.Description.Behaviors.Add(serviceBehaviour); webServiceHost.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexHttpBinding(), “mex”); var httpBinding = new BasicHttpBinding(); […]