当我打电话给我的webservice时,我会得到两个参数:
从客户端(&)检测到潜在危险的Request.Path值.
Routeconfig:
config.Routes.MapHttpRoute(
name: "PropertiesSearch",
routeTemplate: "api/property/Search/{category}/{query}",
defaults: new { controller = "Property", action = "Search", category = "common", query = string.Empty }
);
Run Code Online (Sandbox Code Playgroud)
Controllermethod:
[HttpGet]
public SearchResult Search(string category, string query)
{
}
Run Code Online (Sandbox Code Playgroud)
当我打电话给api时:
/ API /属性/搜索/家庭/ areaID表示%3D20339%26areaId%3D20015
从客户端(&)检测到潜在危险的Request.Path值.
这样做:
/ API /属性/搜索/家庭/?查询= areaID表示%3D20339%26areaId%3D20015
工作良好.
如何解决路由解码问题?
如何在c#中以编程方式使用证书身份验证设置ServiceClient?
我不想使用.config.
using(var srv = GetServiceInstance())
{
srv.DoStuff()
}
private TheServiceClient GetServiceInstance()
{
var service = new TheServiceClient(CreateWsHttpBinding(), CreateEndpointAdress());
return service;
}
private static WSHttpBinding CreateWsHttpBinding()
{
var wsHttpBinding = new WSHttpBinding();
wsHttpBinding.Security.Mode = SecurityMode.Message;
wsHttpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
wsHttpBinding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None;
wsHttpBinding.Security.Transport.Realm = "";
wsHttpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
wsHttpBinding.Security.Message.NegotiateServiceCredential = true;
wsHttpBinding.Security.Message.ClientCredentialType = MessageCredentialType.Certificate;
wsHttpBinding.Name = "Bindingname";
wsHttpBinding.CloseTimeout = TimeSpan.FromMinutes(1);
wsHttpBinding.OpenTimeout = TimeSpan.FromMinutes(1);
wsHttpBinding.ReceiveTimeout = TimeSpan.FromMinutes(10);
wsHttpBinding.SendTimeout = TimeSpan.FromMinutes(1);
wsHttpBinding.BypassProxyOnLocal = false;
wsHttpBinding.TransactionFlow = false;
wsHttpBinding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
wsHttpBinding.MaxBufferPoolSize = 524288; …
Run Code Online (Sandbox Code Playgroud) 当我尝试使用Web服务时,我得到以下异常.我的主要问题是这个例外何时发生?在服务器或客户端?错误在哪里?服务器是否针对各种故障抛出此信息?
我自己做了一些看似有效的改动
它实际上现在有效.我删除了使用并在服务客户端上添加了som清理.
if (Service != null && Service.State != CommunicationState.Faulted)
{
success = true;
Service.Close();
}
}
catch (Exception ex)
{
msg = "Error" + Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace;
}
finally{
if (!success)
{
if (Service != null) Service.Abort();
}
}
Run Code Online (Sandbox Code Playgroud)
这是例外:
The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state.
Server stack trace:
at System.ServiceModel.Channels.CommunicationObject.Close(TimeSpan timeout)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, …
Run Code Online (Sandbox Code Playgroud) 当我调用WCF服务时,我得到一个例外:
已超出传入邮件的最大邮件大小限额(65536).要增加配额,请在相应的绑定元素上使用MaxReceivedMessageSize属性.
当我在http上使用Wireshark数据包分析器过滤器发送的大数据包为1226字节时,其方式低于65536字节的限制.为什么抛出此异常的任何建议?
Protocole - 长度 - 信息
服务器堆栈跟踪:
at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter)
at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Exception rethrown at [0]:
...
<binding
name="WSHttpBinding_IService"
closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false"
transactionFlow="false"
hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas
maxDepth="32"
maxStringContentLength="8192"
maxArrayLength="16384"
maxBytesPerRead="4096"
maxNameTableCharCount="16384" />
<reliableSession
ordered="true"
inactivityTimeout="00:10:00"
enabled="false" />
<security
mode="Message"> …
Run Code Online (Sandbox Code Playgroud) 我已经使用如下属性定义了一个partial类:
public partial class Item{
public string this[string key]
{
get
{
if (Fields == null) return null;
if (!Fields.ContainsKey(key))
{
var prop = GetType().GetProperty(key);
if (prop == null) return null;
return prop.GetValue(this, null) as string;
}
object value = Fields[key];
return value as string;
}
set
{
var property = GetType().GetProperty(key);
if (property == null)
{
Fields[key] = value;
}
else
{
property.SetValue(this, value, null);
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
所以我可以这样做:
myItem["key"];
Run Code Online (Sandbox Code Playgroud)
并获取Fields字典的内容.但当我建立我得到:
"成员名称不能与其封闭类型相同"
为什么?
我的asp.net站点中有一些requiredFileldvalidators,我想在需要之前设置隐形.但是,当我将它们设置为visible = false时,它们不会触发.如果它们设置为visible = true,它们就可以工作.
这是此控件的正确行为还是错误的.我希望它们在可见时由于样式问题而不可见.
我想在WinForm上创建一系列RadioButton.它工作正常,但在Click-event中我想捕获产品ID并用它来做.我习惯于HTML元素,并将数据分配给RadioButton的标签和值.使用WinForms,我看不到与value属性等价的东西.
关于如何将产品ID传递给RadioButton Change-event的任何好建议?
var products = new Business.Products().GetAll();
if (!products.Any())
GrpCategories.Controls.Clear();
int y = 2;
int x = 2;
foreach (var product in products)
{
var btn = new RadioButton();
btn.Width = 100;
btn.Height = 20;
if (y >= GrpCategories.Height - btn.Height - 10)
{
x += btn.Width + 2;
y = 2;
}
y += btn.Height + 2;
btn.Appearance = Appearance.Button;
btn.Text = product.Name;
btn.Name = "BtnProduct_" + product.ID;
btn.Location = new Point(x, y);
GrpCategories.Controls.Add(btn);
}
Run Code Online (Sandbox Code Playgroud) c# ×7
wcf ×3
asp.net ×2
service ×2
.net ×1
asp.net-mvc ×1
radio-button ×1
rest ×1
validation ×1
wcf-binding ×1
wcf-client ×1
wcf-security ×1
winforms ×1