我读了一些关于这个的文章,我发现要获得wcf从我们添加的帖子请求中获取数据
[ServiceContract]
public interface IService1 {
[OperationContract]
[WebInvoke(
Method = "POST",
BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = "/GetData")]
void GetData(Stream data);
}
Run Code Online (Sandbox Code Playgroud)
并在实施中
public string GetData( Stream input)
{
long incomingLength = WebOperationContext.Current.IncomingRequest.ContentLength;
string[] result = new string[incomingLength];
int cnter = 0;
int arrayVal = -1;
do
{
if (arrayVal != -1) result[cnter++] = Convert.ToChar(arrayVal).ToString();
arrayVal = input.ReadByte();
} while (arrayVal != -1);
return incomingLength.ToString();
}
Run Code Online (Sandbox Code Playgroud)
我的问题是我应该怎样做,在表单请求中提交操作会发送到我的服务并消费?
在Stream参数中,我是否可以通过Request ["FirstName"]从表单中获取信息?
我正在尝试构建一个基本的REST Web服务,它只返回当前时间,每当我尝试调用我的服务时,每次尝试时都会出现以下错误http:// localhost:PORT/TimeService/CurrentTime:
端点未找到.请参阅服务帮助页面以构建对服务的有效请求.
我究竟做错了什么?您可以在下面找到我正在使用的所有代码.谢谢
Service1.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Text;
namespace WcfRestService1
{
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
public class TimeService
{
[WebGet(UriTemplate = "CurrentTime")]
public string CurrentTime()
{
return DateTime.Now.ToString();
}
}
}
Run Code Online (Sandbox Code Playgroud)
Global.asax中
using System;
using System.ServiceModel.Activation;
using System.Web;
using System.Web.Routing;
namespace WcfRestService1
{
public class Global : HttpApplication
{
void Application_Start(object sender, EventArgs e)
{
RegisterRoutes();
}
private static void RegisterRoutes()
{
RouteTable.Routes.Add(new …Run Code Online (Sandbox Code Playgroud) 我一直在努力解决问题,任何帮助将不胜感激.
问题:我有一个段落,我想要替换多次出现的变量(变量= @Variable).这是一个简单的部分,但我遇到困难的部分是尝试用不同的值替换变量.
我需要每次出现都有不同的值.例如,我有一个函数可以对每个变量进行计算.我到目前为止的内容如下:
private string SetVariables(string input, string pattern){
Regex rx = new Regex(pattern);
MatchCollection matches = rx.Matches(input);
int i = 1;
if(matches.Count > 0)
{
foreach(Match match in matches)
{
rx.Replace(match.ToString(), getReplacementNumber(i));
i++
}
}
Run Code Online (Sandbox Code Playgroud)
我能够用getReplacementNumber(i)函数返回的数字替换我需要的每个变量,但是如何用匹配集合中找到的相同顺序将它放回到我的原始输入中的替换值?
提前致谢!
马库斯
我在WP7上使用silverlight.我有一个班级,我正在尝试序列化到隔离存储.我知道框架会自动为我自动序列化,假设每个属性都是可序列化的.
对于这个类,我有一些不可序列化的属性(如BitmapImage).有没有办法告诉框架不序列化该属性(而是在反序列化时将其设置为null?)
我知道实现XmlSerializable是一种可能性,但我不想手动设置/获取每个.我宁愿它序列化我告诉它的内容,并且我可以在反序列化之后设置其他属性.
谢谢
c# silverlight serialization xml-serialization windows-phone-7
我已经制作了一个REST Web服务,它与Visual Studios WCF测试客户端一起使用.可以使用位于其旁边的网站调用它,并使用使用svcutil创建的"代理"类.
当我浏览到.svc文件时,我也可以看到服务存在.(http://localhost/service1.svc)它提出了"你已经创建了一个服务".网页.
然而
当我尝试调用服务中的函数(http://localhost/service.svc/firstName/lastName)时,它返回400错误代码.
我最近有一个单独的错误,我无法弄清楚所以我找到了一个关于非常基本的Web服务的教程" http://blog.weareon.net/how-to-create-and-consume-rest-web-service- using-wcf / ",那个停止了上一个错误,但在尝试调用函数时仍然有400错误.
我的.config文件被削减到了骨头,以便在我进入太远之前尝试让它工作.
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name="VService">
<endpoint address="" binding="webHttpBinding" contract="ServiceName.IService1" behaviorConfiguration="webBehavior" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="webBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
<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 …Run Code Online (Sandbox Code Playgroud) 我想使用System.Reflection.Emit命名空间为2D数组构造生成IL .
我的C#代码是
Array 2dArr = Array.CreateInstance(typeof(int),100,100);
Run Code Online (Sandbox Code Playgroud)
使用ildasm,我意识到为上面的C#代码生成了以下IL代码.
IL_0006: call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
IL_000b: ldc.i4.s 100
IL_000d: ldc.i4.s 100
IL_000f: call class [mscorlib]System.Array [mscorlib]System.Array::CreateInstance(class [mscorlib]System.Type,
int32,
int32)
Run Code Online (Sandbox Code Playgroud)
我能够生成最后三个IL语句,如下所示.
MethodInfo createArray = typeof(Array).GetMethod("CreateInstance",
new Type[] { typeof(Type),typeof(int),typeof(int) });
gen.Emit(OpCodes.Ldc_I4_1);
gen.Emit(OpCodes.Ldc_I4_1);
gen.Emit(OpCodes.Call, createArray);
Run Code Online (Sandbox Code Playgroud)
但我不清楚如何生成拳头IL声明(即IL_0006: call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle))
你有什么主意吗?
此外,有人能指出一些关于如何使用System.Reflection.Emit命名空间以生成IL代码的好教程/文档吗?
请参阅此图片,我将其称为静态框:

我不确定这是不是这个名字.
盒子应该能够容纳任意儿童控制(面板等).
我有一个非常愚蠢的问题,但由于某种原因,我无法在网上找到任何治疗或信息.
简介:我无法向WebGet方法传递多个参数.如果我这样做,服务器返回HTTP 500错误,该方法不会执行.我的代码和请求如下.
[ServiceContract]
public class WebmailAPI {
...
[WebGet(UriTemplate= "Webmail?messagetype={messageType}&unreadonly={unreadOnly}&skip={skip}&take={take}")]
public void Get(MessageType messageType, bool unreadOnly, int skip, int take) {
...
}
}
Run Code Online (Sandbox Code Playgroud)
Global.ASAX.CS:routes.SetDefaultHttpConfiguration(new WebApiConfiguration(){EnableHelpPage = true,EnableTestClient = true}); RouteTable.Routes.MapServiceRoute( "API /");
此请求执行正常: http:// localhost:9000/api/Webmail /?messagetype = 1
这个返回500错误:
HTTP://本地主机:9000/API /网络邮件/为messageType = 1&unreadonly = 0&跳过= 0&取= 100
信息:VS2010 SP1 + ASP.NET 4 +实体框架2001年6月CTP +最新的WebAPI
在此先感谢您的帮助!
PS我试图在查询字符串中对"&"进行HTML编码 - 没有效果.
我实现了一个PagedModel类来包装IEnumerable,为我的MVC应用程序中的网格提供分页数据.我使用了Resharper自动生成的Equality代码,告诉它检查数据,总行数,页码和页面大小字段.这是类代码:
Public Class PagedModel(Of T)
Public Property PageSize As Integer
Public Property PageNumber As Integer
Public Property ModelData As IEnumerable(Of T)
Public Property TotalRecords As Integer
Public Overloads Function Equals(ByVal other As PagedModel(Of T)) As Boolean
If ReferenceEquals(Nothing, other) Then Return False
If ReferenceEquals(Me, other) Then Return True
Return other._PageSize = _PageSize AndAlso other._PageNumber = _PageNumber AndAlso Equals(other._ModelData, _ModelData) AndAlso other._TotalRecords = _TotalRecords
End Function
Public Overloads Overrides Function Equals(ByVal obj As Object) As Boolean
If ReferenceEquals(Nothing, obj) Then Return …Run Code Online (Sandbox Code Playgroud) 我想将json对象发布到我的WCF服务中
我唯一的问题是他的约会属性。我从一个jQuery datepicker获取日期,我想以c#datetime在我的服务中获取它。
我的服务:
namespace Employee
{
[ServiceContract]
public interface IService1
{
[OperationContract]
[WebInvoke(Method = "POST",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped)]
bool UpdateEmployee(Employee Employee);
}
}
Run Code Online (Sandbox Code Playgroud)
这是员工:
[DataContract]
public class Employee
{
[DataMember]
public string Name { get; set; }
[DataMember]
public string Department { get; set; }
[DataMember]
public int Salary { get; set; }
[DataMember]
public DateTime Hired { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
所有其他属性都可以正常工作。我只需要将我的日期字符串转换为json日期。
c# ×6
wcf ×5
asp.net ×3
rest ×2
.net ×1
datepicker ×1
equals ×1
forms ×1
il ×1
json ×1
overloading ×1
post ×1
silverlight ×1
vb.net ×1
wcf-web-api ×1
web-services ×1
wpf ×1
wpf-controls ×1