我们正在开发一个与WCF服务一起使用的桌面Windows 8应用程序.我们希望启用Azure WCF服务和本地网络中的WCF服务(可选).应用程序将在Windows应用商店中发布.在公司的本地服务器上部署WCF服务的最佳实践是什么?
我在c#中编写了一个wcf服务.从Jquery我调用该服务并返回一个列表.我现在想要返回多个列表.这可能吗?
该列表将作为Json传回.我可以以某种方式创建一个列表数组?对不起,我是新手,所以这个问题可能太模糊了.
使用WCF传输子类时遇到一些问题.我想创建一个通用的"反馈"类,并从反馈中继承:Succes-class和Failure-class(失败有错误代码和描述).这应该使客户端能够执行以下操作:
If (myWCFclient.authenticate(user, password) is Succes)
{
..
}
Run Code Online (Sandbox Code Playgroud)
在我的WCF datacontracts中,我这样定义:
[DataContract]
public class Feedback : IFeedback
{
}
[DataContract]
public class Succes : Feedback
{
}
[DataContract]
public class Failure : Feedback
{
[DataMember]
public int errorCode { get; set; }
[DataMember]
public String description { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
这很有效,我的运营合同如下:
[OperationContract]
Feedback Authenticate(String email, String password);
Run Code Online (Sandbox Code Playgroud)
但是在我的"客户端"应用程序中,我收到了这些课程,我只发现"反馈"作为一个类,"Succes"和"Failure"无处可寻.

有谁知道我做错了什么?我应该在我的DataContracts中定义那些不同的"Succes"和"Failure"类,因为它们是"反馈"的子类吗?
提前致谢.
如何从自托管WCF 4.5服务获取JSON?
我正在使用Fiddler2发送带有"Content-Type:application/json"的请求(也尝试过"Content-Type:application/javascript"),但我一直在使用XML.
结合在我的WebHttpBehavior上设置"AutomaticFormatSelectionEnabled = true",我仍然得到XML,当使用"Content-Type:application/json"时,服务器根本不会响应(然后我得到错误103)
我在WebHttpBinding上启用了CrossDomainScriptAccessEnabled,并且我在控制台主机中使用了WebServiceHost.
服务很简单:
[ServiceContract]
public interface IWebApp
{
[OperationContract, WebGet(UriTemplate = "/notes/{id}")]
Note GetNoteById(string id);
}
Run Code Online (Sandbox Code Playgroud)
我也尝试将AutomaticFormatSelectionEnabled设置为false并在我的服务合同中使用ResponseFormat = WebMessageFormat.Json,但这也导致"错误103"没有进一步的信息.
我已经转换了customErrors并将FaultExceptionEnabled,HelpEnabled设置为true(不确定是否会对此做任何事情但只是为了确保我已经尝试过所有这些)
我错过了一个dll还是别的什么?
嗨,我只是在学习WCF,并且正在尝试为现有的ASP.NET MVC 4应用程序创建Web服务.这是我到目前为止所做的:
我已经创建了一个WCF服务应用程序.我定义了数据契约和数据成员:
[DataContract]
public class BookData
{
[DataMember]
public int Id { get; set; }
[DataMember]
public string Name { get; set; }
[DataMember]
public string Author { get; set; }
[DataMember]
public string Description { get; set; }
[DataMember]
public DateTime PublicationDate { get; set; }
[DataMember]
public int CategoryId { get; set; }
[DataMember]
public decimal Price { get; set; }
[DataMember]
public string BookUrl { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我已经定义了服务合同:
[ServiceContract]
public interface IBookService
{ …Run Code Online (Sandbox Code Playgroud) 我正在尝试构建一个相当基本的WCF SOAP Web服务,作为Windows服务自托管.Windows服务本身在我的机器上启动并运行 - 我无法通过Visual Studio或Web浏览器在本地访问它.
相关的C#代码如下.假设MyDummyService实施合同IDummyService:
public class Program : ServiceBase
{
private ServiceHost host = null;
private readonly Uri baseAddress = new Uri("http://localhost:8000/DummyAPI");
public static readonly ILog log = LogManager.GetLogger(typeof(Program));
/// <summary>
/// The main entry point for the application.
/// </summary>
public static void Main(string[] args)
{
ServiceBase.Run(new Program());
}
public Program()
{
this.ServiceName = "DummyService";
}
protected override void OnStart(string[] args)
{
log.Info("Starting service");
try
{
base.OnStart(args);
host = new ServiceHost(typeof(MyDummyService), baseAddress); …Run Code Online (Sandbox Code Playgroud) 我想DataSet从WPF应用程序发送到WCF服务.当我发送一个空的DataSet它工作正常.但是DataSet30岁的DataTable它给了我一个例外
远程服务器返回意外响应:(400)错误请求.
我的运营合同是:
[OperationContract]
string InsertDataToDatabase(DataSet ds);
Run Code Online (Sandbox Code Playgroud)
哪个是发送DataSet到WCF服务的最佳方式?
客户 App.Config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ICommunication" 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="2147483647"
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:49486/Communication.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ICommunication"
contract="CommunicationReference.ICommunication" name="BasicHttpBinding_ICommunication" />
</client>
</system.serviceModel>
</configuration>
Run Code Online (Sandbox Code Playgroud)
服务 Web.Config
<?xml …Run Code Online (Sandbox Code Playgroud) 嘿伙计们,当我的申请结束时,我得到了这个例外.CustomerReadySub是我订阅的活动.
错误发生在这一行
fTypeLabel.Invoke(new MethodInvoker(fuelTypeChosen));
public void CustomerReadySub(object sender, CustomerReadyEventArgs fuel)
{
// code to handle the event
string CustReady = null;
//checks what fuel is chosen and then activates the pump
fuelType = fuel.SelectedFuel.ToString();
if (!String.IsNullOrEmpty(fuelType))
{
fTypeLabel.Invoke(new MethodInvoker(fuelTypeChosen));
if (fuelType == "Unleaded") //checks fuel type and displays price accordingly
{
pplText.Invoke(new MethodInvoker(petrol));
}
else
{
pplText.Invoke(new MethodInvoker(diesel));
}
CustReady = "READY";
WCFPump.sendReady(CustReady);
}
while (WCFPump.getOK() == 0) { /*do nothing*/} //used to loop around until OK is retrieved
if …Run Code Online (Sandbox Code Playgroud) 我在wcf服务中有这样的方法
public string PostAllSurveList(List<Survey> surveyList)
{
var surveyDbList = ConstructDbServeyList(surveyList);
foreach (var survey in surveyDbList)
{
_db.surveys.Add(survey);
}
_db.SaveChanges();
return "Successfully Saved";
}
Run Code Online (Sandbox Code Playgroud)
当我通过以下方式在C#中调用此方法时,它工作正常
var surveys = new Survey[]{new Survey{ Id = 1, ConsumerName = "atish"},};
string reply = client.PostAllSurveList(surveys);
Run Code Online (Sandbox Code Playgroud)
但不是以下列方式工作
var surveys = new List<Survey>{ new Survey { Id = 1, ConsumerName = "atish"}};
string reply = client.PostAllSurveList(surveys);
Run Code Online (Sandbox Code Playgroud)
得到编译时错误.
我的问题是为什么会这样.
奇怪的是我在谷歌上找不到任何东西.在做常规异常时你会创建一个MyCustomException : Exception,我假设同样适用于ExceptionFaults.
当有人使用无效的api密钥调用我的服务时,我想抛出一个InvalidApiKeyExceptionFault.我似乎无法在网上找到如何设置它并让客户端能够捕获它的示例(可能是某个地方将其包含在WSDL中).
任何建议在哪里看,或者我在尝试一些不可能的事情?
wcf ×10
c# ×6
json ×2
class ×1
deployment ×1
exception ×1
fault ×1
inheritance ×1
invoke ×1
jquery ×1
list ×1
rest ×1
self-hosting ×1
soap ×1
web-services ×1
windows-8 ×1