我有一个存储用户上传的文件server.Now文档(PDF文件)的WCF服务,我想这些PDF文件转换为字节,因此在iOS客户端可以下载他们iPad.I不想存储PDF文件作为SQL中的BLOB,只需转换为字节并将它们发送到iPad.任何实现此目的的链接/示例代码都非常感谢.
阅读有关使用ServiceHostFactory扩展主机的MSDN教程,有一个覆盖CreateServiceHost函数的示例:
public class DerivedFactory : ServiceHostFactory
{
public override ServiceHost CreateServiceHost( Type t, Uri[] baseAddresses )
{
return new DerivedHost( t, baseAddresses )
}
}
Run Code Online (Sandbox Code Playgroud)
但是,当我们查看类的实际定义时,CreateServiceHost方法是protected:
protected virtual ServiceHost CreateServiceHost(
Type serviceType,
Uri[] baseAddresses
)
Run Code Online (Sandbox Code Playgroud)
我的问题是,我应该覆盖什么?MSDN示例错了吗?
我实现了一个自定义消息检查器(通过IDispatchMessageInspector)来拦截在WCF服务的服务器端接收的消息,因此我可以尝试反序列化消息并应用一些特定的业务逻辑.我遇到的问题是当我将MessageBuffer的内容写入新的MemoryStream然后尝试反序列化时,我收到一条错误,指出"根级别的数据无效.第1行,第1位".我知道传入的数据是有效的,因为跳过检查器可以使一切正常.
示例代码:
public object AfterReceiveRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel, System.ServiceModel.InstanceContext instanceContext)
{
MessageBuffer buffer = request.CreateBufferedCopy(Int32.MaxValue);
request = buffer.CreateMessage();
string msg = buffer.CreateMessage().ToString();
var dc = new DataContractSerializer(typeof(Adder));
using (var stream = new MemoryStream())
{
buffer.WriteMessage(stream);
stream.Position = 0;
//deserializing error occurs here
var c = dc.ReadObject(stream);
}
return null;
}
Run Code Online (Sandbox Code Playgroud)
这是Adder类/接口:
[DataContract(Name = "adder", Namespace = "http://test.com")]
public class Adder
{
[DataMember(Name = "first")]
public int First { get; set; }
[DataMember(Name = "second")]
public int Second { get; …Run Code Online (Sandbox Code Playgroud) 我对Web服务不是很清楚.我创建了一个Web服务,并使用visual studio中的发布选项将其托管在IIS上.有什么方法可以通过IIS管理器在IIS(不使用visual studio)上托管我的应用程序.
我有以下简单的WCF库,它是在Visual Studio 2008上开发的.
当运行调用此wcf服务的WCFTestClinet/javascript(使用SOAP)时,我得到以下场景的错误值:
1.GetNumber - > output:"您的号码是0"
2.SetNumber - >无输出
3. GetNumber - >输出:"你的号码是0" 而不是输出:"你的号码是8"!!!
任何人都可以解释为什么会发生这种情况,我该如何解决?
谢谢
public class Service1 : IService1
{
private int Number;
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
public CompositeType GetDataUsingDataContract(CompositeType composite)
{
if (composite.BoolValue)
{
composite.StringValue += "Suffix";
}
return composite;
}
public string GetNumber()
{
return string.Format("Your number is : {0}", Number);
}
public void SetNumber()
{
Number = 8;
}
}
Run Code Online (Sandbox Code Playgroud) 我已经为以下所有设置了一致的命名空间(http://somenamespace.com/2012/10/):
但是我在服务日志(.svclog)文件上收到此错误.有人可以开导我这个吗?我已经咨询了几个网站,但无济于事.
这是一个很好的参考:http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/ee11d86f-f25c-4284-8f51-b1f035346cb3/
<E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent">
<System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system">
<EventID>131074</EventID>
<Type>3</Type>
<SubType Name="Error">0</SubType>
<Level>2</Level>
<TimeCreated SystemTime="2013-01-04T06:57:48.7620812Z" />
<Source Name="System.ServiceModel" />
<Correlation ActivityID="{eadc96c2-323f-41df-bc3d-df56367dda52}" />
<Execution ProcessName="w3wp" ProcessID="2088" ThreadID="54" />
<Channel />
<Computer>SOMECOMPUTER007</Computer>
</System>
<ApplicationData>
<TraceData>
<DataItem>
<TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Error">
<TraceIdentifier>http://msdn.microsoft.com/en-US/library/System.ServiceModel.Diagnostics.EventLog.aspx</TraceIdentifier>
<Description>Wrote to the EventLog.</Description>
<AppDomain>/LM/W3SVC/1/ROOT/SomeApplication-1-130017541311895789</AppDomain>
<ExtendedData xmlns="http://schemas.microsoft.com/2006/08/ServiceModel/DictionaryTraceRecord">
<CategoryID.Name>EventLogCategory</CategoryID.Name>
<CategoryID.Value>7</CategoryID.Value>
<InstanceID.Name>EventId</InstanceID.Name>
<InstanceID.Value>3221356549</InstanceID.Value>
<Value0>System.ArgumentException: The 'http://somenamespace.com/2012/10/' namespace is not defined.
at System.Xml.XmlWriter.WriteQualifiedName(String localName, String ns)
at System.Runtime.Serialization.XmlWriterDelegator.WriteAttributeQualifiedName(String attrPrefix, XmlDictionaryString attrName, XmlDictionaryString attrNs, XmlDictionaryString name, XmlDictionaryString ns) …Run Code Online (Sandbox Code Playgroud) 是否有可能在WCF中将DbConnection作为OperationConstract的参数发送?因为我得到的数据合同名称的SqlConnection异常"类型System.Data.SqlClient.SqlConnection:HTTP://schemas.datacontract.org/2004/07/System.Data.SqlClient预计不会考虑使用DataContractResolver或添加任何.静态地知道已知类型列表的类型 - 例如,通过使用KnownTypeAttribute属性或将它们添加到传递给DataContractSerializer的已知类型列表中.
我盯着 web.config 看了很久,你们能看一下吗?
运行service.Endpoint.Address.ToString()给了我预期的结果:http://localhost:2867/Service1.svc并http://localhost:2867/Service1.svc?wsdl给了我所需的所有方法。
如果您需要更多信息/代码,我很乐意添加它。
感谢您的浏览!
错误
没有侦听端点http://localhost:2867/Service1.svc可以接受该消息。这通常是由不正确的地址或 SOAP 操作引起的。
客户端配置
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="webpages:Version" value="2.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="PreserveLoginUrl" value="true" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<system.web>
<httpRuntime targetFramework="4.5" />
<compilation debug="true" targetFramework="4.5" />
<pages>
<namespaces>
...
</namespaces>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
...
</handlers>
</system.webServer>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1" />
<binding name="Identity Management WebserviceSoap">
<security mode="Transport" /> …Run Code Online (Sandbox Code Playgroud) 我正在尝试运行我的 WCF 服务,但出于某种原因我总是遇到以下错误:
'' 处的端点没有与 None MessageVersion 的绑定。“System.ServiceModel.Description.WebHttpBehavior”仅适用于 WebHttpBinding 或类似的绑定。
网络配置
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5">
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
<httpRuntime targetFramework="4.5" />
</system.web>
<system.serviceModel>
<services>
<service behaviorConfiguration="Default" name="AF_ES.SG">
<endpoint address="rest" behaviorConfiguration="webBehavior" binding="webHttpBinding" contract="AF_ES.IServices.ISG" />
<endpoint address="soap" behaviorConfiguration="soapBehavior" binding="basicHttpBinding" contract="AF_ES.IServices.ISG" />
</service>
</services>
<behaviors> …Run Code Online (Sandbox Code Playgroud) 我正在使用 WCF 休息服务,我想返回总记录数,就像我们在 webapi 或 Breeze 中拥有内联计数一样。
我在WCF中的方法是
[WebGet(UriTemplate = "GiveMeNamesOfStudents", ResponseFormat = WebMessageFormat.Json)]
public List<MyDataClass> GiveMeNamesOfStudentsList()
{
var returnData = (from myentity in myEntityRepository.AsQueryable()
select new MyDataClass
{
Id = myentity.Id,
Name = myentity.Name
}).Skip(PageSize * PageNo).Take(PageSize).ToList();
return returnData;
}
Run Code Online (Sandbox Code Playgroud)
如何返回实际数据的总记录数和数据?
wcf ×10
c# ×8
.net ×5
soap ×2
asp.net-mvc ×1
dbconnection ×1
exception ×1
iis ×1
javascript ×1
linq ×1
wcf-binding ×1
wcf-rest ×1
web-config ×1
web-services ×1