Tag: #wcf

WCF:“为MTOM消息创建阅读器时出错”

试图让MTOM在WCF客户端中工作。 我正在尝试使用的特定函数发送一个PDF文档的MTOM编码字节数组。 使用SoapUI使用WSDL测试API工作正常; 但是,当我尝试在客户端中执行相同的操作时,我收到以下错误: Error creating a reader for the MTOM message System.Xml.XmlException: MTOM messages must have type ‘application/xop+xml’. at System.Xml.XmlMtomReader.ReadMessageContentTypeHeader(ContentTypeHeader he ader, String& boundary, String& start, String& startInfo) at System.Xml.XmlMtomReader.Initialize(Stream stream, String contentType, Xml DictionaryReaderQuotas quotas, Int32 maxBufferSize) at System.Xml.XmlMtomReader.SetInput(Stream stream, Encoding[] encodings, Str ing contentType, XmlDictionaryReaderQuotas quotas, Int32 maxBufferSize, OnXmlDic tionaryReaderClose onClose) at […]

WCF中的动态ExpandoObject

尝试使用枚举类型过程和动态数据操作Ping / Pong我的服务。 [ServiceContract ( CallbackContract = typeof ( iStackoverflowCallBack ) )] public interface iStackoverflow { [OperationContract] void Ping ( Process Operation , dynamic Data ); } [ServiceContract ( )] public interface iStackoverflowCallBack { [OperationContract] void Pong ( Process Operation , dynamic Data ); } 为什么这项服务有连接问题? 当实现两个接口时, dynamic自动转换为object 。 当从消费者ping我的服务时,ping根本不会到达服务,但服务正常工作。 方案: [DataContract] public class SerializableDynamicObject […]

400错误请求将xml有效负载发送到WCF REST服务

我知道有几篇post询问400错误,我相信我已经阅读了所有这些错误,但我认为我面临的问题是不同的。 这是我的WCF服务合同 [WebInvoke(UriTemplate = “/cust_key/{key}/prod_id/{id}”, Method = “POST”, BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Xml)] Stream GetData(string key, string id, string data); 这是我用来将请求发送到我的restsvc的代码 request.RequestUri = new Uri(“http://localhost:3138/v1/cust_key/company1/prod_id/testProductID”); request.ContentType = “application/xml”; request.HttpMethod = “POST”; string xml = @”dell 400400 dollars”; byte[] message = Encoding.ASCII.GetBytes(xml); string data = Convert.ToBase64String(message); response = request.MakeWebRequest(null, data); 这给了我400个错误请求错误。 我试图将xml字符串更改为以下两个,它们也会产生400错误 […]

为什么WCF不能传递字典中的对象?

在我的WCF服务中,我将对象QualifiedNumber定义为KnownType和ServiceKnown类型。 如果我在以下方法中使用QualifiedNumber : 这个不起作用。 它抛出一个exception,部分内容如下: 元素’ http://schemas.microsoft.com/2003/10/Serialization/Arrays:Value ‘包含’ http://schemas.datacontract.org/2004/07 ServiceLibrary.Web.Model:QualifiedNumber’数据合同的数据。 反序列化器不知道映射到此合同的任何类型。 无法反序列化,因为QualifiedNumber的定义未知。 [OperationContract] public Dictionary TestDictionaryGet() { Dictionary retDict = new Dictionary(); retDict.Add(1, new QualifiedNumber(new decimal(1.2), “<")); retDict.Add(2, "pass a simple string"); return retDict; } 这个工作 public struct element { public int key; public object value; } [OperationContract] public List TestElementListGet() { Dictionary retDict = […]

在RESTful WCF中混合XML和JSON,无需单独的方法

我有一个RESTful WCF服务,可以返回XML,JSON或JSONP,具体取决于参数,例如/service.svc/stuff?format=xml或service.svc/stuff?format=json&callback=myCallback 。 为此,我创建了一个自定义的Behavior,MethodEncoder和MethodEncoderFactory,它处理包装JSONP回调并根据format参数选择writer。 在我的编码器的WriteMessage()方法中,我做了类似的事情 XmlWriter writer = IsXmlRequested() ? XmlDictionaryWriter.CreateTextWriter(stream) : JsonReaderWriterFactory.CreateJsonWriter(stream) message.WriteMessage(writer); 然后,我将我的服务方法定义为只返回JSON但使用我的自定义绑定元素: [OperationContract, JSONPBehavior, WebGet(ResponseFormat = WebMessageFormat.Json, UriTemplate = “stuff”) public List GetStuff(){…} 它几乎可以工作。 当我要求XML或JSON时,我得到了正确格式的东西,但XML没有像我期望的那样被序列化。 这是XML的样子: 1 如果我只是将WebMessageFormat设置为XML,我会得到这样的结果: 1 我绝对想要后者。 我猜这种情况正在发生,因为在创建Message对象时,结果被序列化为字典; 我的自定义编码器只是决定如何将该字典写入响应流。 因此它获得了正确的编码,但不完全是格式,这已经由ResponseFormat决定。 首先,是吗? 如果是这样,我该如何解决这个问题呢? 例如,我可以编写自己的WebMessageFormat吗? 或者我是否只需要为/ json / *和/ xml / *提供不同的ResponseFormat属性的单独方法(和URI模板)? 更新:在.net 4中,您可以设置一个WebOperationContext.Current.OutgoingResponse.Format属性。 我想我的问题归结为:有没有办法在.net 3.5中实现这一目标?

在区域外的MVC应用程序中托管WCF服务

我有一个MVC项目,我在根目录中添加了一个名为WCF的文件夹。 在这个文件夹中,我创建了一个名为CustomFunctions的WCF服务。 当我尝试启动该服务时,收到以下错误: 错误:无法从http://localhost/Viper/WCF/CustomFunctions.svc获取元数据…元数据包含无法解析的引用: 附加说明: 无法找到类型为“Viper.WCF.CustomFunctions”的类型,作为ServiceHost指令中的Service属性值提供,或者在配置元素system.serviceModel / serviceHostingEnvironment / serviceActivations中提供。 昨天我收到了这个错误,花了一些时间在互联网上寻找答案。 这导致我对我的Web.config以及我的Global.asax.cs进行了很多更改。 昨天,它开始工作,我停了下来。 然而,当我今天早上回来时,它再也没有工作。 没有添加任何新内容,也没有更改代码。 我已将以下内容添加到我的Web.config中: 这是我的Global.asax.cs : public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute(“{resource}.svc/{*pathInfo}”); routes.MapRoute( “Default”, // Route name “{controller}/{action}/{id}”, // URL with parameters new { controller = “Home”, action = “Index”, id = UrlParameter.Optional }, // Parameter defaults new { controller = “^(?!CustomFunctions).*” […]

WCF客户端错误:“未指定安全令牌颁发者的地址”

我从WCF客户端收到以下错误。 “未指定安全令牌颁发者的地址。必须在目标’http://site.com/TLAPI.svc’的绑定中指定显式颁发者地址,或者必须在凭据中配置本地颁发者地址。” 我正在尝试连接到SharePoint服务应用程序。 我添加了生成下面的客户端类的服务引用。 到目前为止,这是我的代码: TipAndLeadAPIContractClient client = new TipAndLeadAPIContractClient(@”CustomBinding_ITipAndLeadAPIContract”, @”http://site.com/TLAPI.svc”); client.ChannelFactory.Credentials.SupportInteractive = false; client.ClientCredentials.UserName.UserName = “user”; client.ClientCredentials.UserName.Password = “password”; client.ConvertToTLForm(@”C:\Clients\ServiceApplication\CAP\capsample1.xml”, “tl_library”, “http://site/”); 这是我的客户端绑定配置: 这是我的服务应用程序绑定配置: 提前致谢。

WCF测试客户端:无法添加服务。 可能无法访问服务元数据。 确保您的服务正在运行并公开元数据

我目前正在尝试使用同步框架示例: sample 该解决方案可以编译出任何错误或警告。 但是当我点击F5时,WCF测试客户端启动并抛出以下错误。 Local \ Temp \ Test Client Projects \ 10.0 \ 5b6aab8a-6629-4a12-87c2-e9e75ba9c1e4 \ Client.cs(379,13):错误CS0246:找不到类型或命名空间名称’schema’(您是否错过了使用指令或程序集引用?) 以下是Client.cs中上述错误引用的代码 /// [System.CodeDom.Compiler.GeneratedCodeAttribute(“svcutil”, “4.0.30319.1”)] [System.SerializableAttribute()] [System.Diagnostics.DebuggerStepThroughAttribute()] [System.ComponentModel.DesignerCategoryAttribute(“code”)] [System.Xml.Serialization.XmlTypeAttribute(Namespace=”http://schemas.datacontract.org/2004/07/Microsoft.Synchronization”)] public partial class SyncIdFormatGroup { private schema schemaField; private System.Xml.XmlElement anyField; /// [System.Xml.Serialization.XmlElementAttribute(Namespace=”http://www.w3.org/2001/XMLSchema”, Order=0)] public schema schema { get { return this.schemaField; } set { this.schemaField = value; } } […]

为什么我使用KnownType属性错误?

我试图从谷歌api反序列化一个json响应,所以我想我会定义几个类来帮助它: [DataContract] public class DetectionResult:ResponseData { [DataMember(Name=”language”)] public string Language { get; set; } [DataMember(Name=”isReliable”)] public bool IsReliable { get; set; } [DataMember(Name=”confidence”)] public double Confidence {get;set;} } [DataContract] public abstract class ResponseData { [DataMember(Name = “error”)] public TranslationError Error { get; set; } } [DataContract] public class TranslationError { [DataMember(Name=”code”)] public int Code { […]

WCF:运行服务器项目时的PlatformNotSupportedException

我提前道歉,因为太过模糊,如果你需要任何精确度,我会尽力给予它。 我编译了2个不同的WCF“代码项目”示例应用程序,无论我发布的是什么,我都会遇到以下exception,所以我猜我的机器上有一些配置错误: 编辑 我尝试了另一台机器(相同的操作系统,赢得7 64),它工作正常。 我只是无法弄清楚我的电脑上有什么配置错误或丢失。 {“Operation is not supported on this platform.”} at System.Net.HttpListener..ctor() at System.ServiceModel.Channels.SharedHttpTransportManager.OnOpen() at System.ServiceModel.Channels.TransportManager.Open(TransportChannelListener channelListener) at System.ServiceModel.Channels.TransportManagerContainer.Open(SelectTransportManagersCallback selectTransportManagerCallback) at System.ServiceModel.Channels.HttpChannelListener.OnOpen(TimeSpan timeout) at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) at System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan timeout) at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout) at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) at WCFService.MainForm.startWCFServer() in D:\xxx\MainForm.cs:line 77 以下是代码。 我猜没有什么不寻常的基本WCF东西。 private ServiceHost host = null; public void […]