我正在尝试创建我的第一个WCF restful服务.在VS2010中,我打开weddingservice.svc,然后点击F5.浏览器打开到http:// localhost:50043/weddingservice.svc 但是,这是我得到的错误:
Server Error in '/' Application.
The type 'RestService.weddingservice', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: The type 'RestService.weddingservice', provided as the Service attribute value in the ServiceHost …
Run Code Online (Sandbox Code Playgroud) 我正在尝试从本地计算机上调用Web服务.但是我在Chrome控制台中遇到以下错误:
http://www.test.com/service.svc/api/?cid=1 405 (Method Not Allowed)
XMLHttpRequest cannot load http://www.test.com/service.svc/api/?cid=1.
Origin http://localhost is not allowed by Access-Control-Allow-Origin.
我的本地测试网址是:
http://localhost/welcome/html/index.html
当我将代码上传到实际域并从那里调用web服务时,它确实可以正常工作.
我已经尝试更改访问控制标头,但这没有帮助.
Namespace RestService
Public Class service
Implements Iservice
Public Function GetProvinces(ByVal cid As String) As AjaxControlToolkit.CascadingDropDownNameValue() Implements Iweddingservice.GetProvinces
WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Methods", "DELETE, POST, GET, OPTIONS")
WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*")
Dim MyConnection As SqlConnection = GetConnection()
Dim cmd As New SqlCommand("SELECT provinceid,title FROM provinces WHERE CountryID=@CountryID ORDER BY title ASC", MyConnection)
cmd.Parameters.Add(New SqlParameter("@CountryID", cid))
Dim values As New List(Of CascadingDropDownNameValue)
Try
MyConnection.Open()
Dim reader As …
Run Code Online (Sandbox Code Playgroud) 我现在验证电子邮件地址如下:
[-+.'\w]+@[-.\w]+\.[-.\w]+
Run Code Online (Sandbox Code Playgroud)
这意味着如果用户意外地在该地址中具有尾随或前导空格(例如,在复制/粘贴时),则表达式验证为false.
所以我想在上面的表达式中允许尾随和前导空格.我怎么能这样做?
我有以下SQL语句:
select pc.*,au.UserName from ProspectsInCampaigns pc
inner join prospects p on p.id=pc.prospectid
inner join aspnet_Users au on STR(au.UserId)=pc.updatedby
WHERE p.id=1225982
Run Code Online (Sandbox Code Playgroud)
问题是,ProspectsInCampaigns中的updatedby字段包含一个空字符串或一个确实是UUID的字符串.在上面的例子中我得到错误:
操作数类型冲突:uniqueidentifier与float不兼容
我怎样才能防止这种情况发生?
我用我的代码隐藏调用这个函数:
DeleteFile(Server.MapPath("/")+"sitemap_index.xml")
Public Shared Function DeleteFile(ByVal filename As String) As Boolean
'deletes file from server
Dim bResult As Boolean = False
Try
If File.Exists(filename) Then
'delete file
File.Delete(filename)
bResult = True
Else
bResult = True
End If
Catch ex As Exception
End Try
Return bResult
End Function
Run Code Online (Sandbox Code Playgroud)
然后我得到错误:拒绝访问路径'E:\ zz\wwwroot\sitemap_index.xml'.
在我自己的其他网站中,这种逻辑很有效,但是在当前的网站上并没有.我检查了我的Windows Server 2008 R2 Standard上的安全设置.
请在此处查看我在Windows服务器上的wwwroot文件夹中的设置:
SYSTEM:完全控制
网络服务:读取+写入+读取和执行+列出文件夹内容
IIS_IUSRS:读取+写入
正如我读过的其他帖子所建议的那样,我尝试添加其他用户组,但我的服务器上没有ASPNET服务/组.
以管理员身份登录(Forms身份验证)时,我可以单击按钮重新创建sitemap_index.xml和sitemaps.xml
用户应该能够删除并添加图像到wwwroot\images\uploads文件夹
我应该赋予哪些组权限以允许上述内容可以安全?
我想将字符串转换为小数,然后转换为字符串,然后再转换为小数.
我试过了:
Dim s As String = "0.7655"
CDec(sDec).ToString("0.00") 'results in: 7653,00
CDec(sDec).ToString 'results in: 7648
CDec(sDec).ToString("N") 'results in: 7.653,00
Run Code Online (Sandbox Code Playgroud)
所以这些都不起作用!
没有简单的函数可以将精确的十进制再次转换为其字符串表示吗?对于这么简单的任务来说,似乎工作太多了!
最好不要格式化字符串,因为在这种情况下我似乎事先知道结果字符串应该有多少个字符.将它转换为字符串后,我还想再将它转换回小数.
我想[listings]
根据相同的用户ID值从[ads]表中选择标题列和列表的出现次数.
结果应如下所示:
[title] [cnt]
Acme 5
MSFT 10
GOOG 7
Run Code Online (Sandbox Code Playgroud)
等等
这不起作用:
select
l.title,
(COUNT (id) FROM ads WHERE ads.userid = l.userid) as cnt
from
listings l
INNER JOIN
ads a on a.userid = l.userid
WHERE
l.listingtype = 2
Run Code Online (Sandbox Code Playgroud) 我有一个约有50个项目的选择,这里是一个小样本.我想检查select是否包含特定的确切值,因此在查找"Beauty"时,这将是1匹配而不是2.
我想过循环遍历所有项目,但后来我遇到了这个:http: //api.jquery.com/is/
并认为可能表现更好.但是,我不知道如何在这段代码上使用它:
<select id="mydropdown" class="textbox">
<option value="Beauty">Beauty</option>
<option value="Catering">Catering</option>
<option value="Beautysalon">Beautysalon</option>
</select>
Run Code Online (Sandbox Code Playgroud) 某些XSD文件会在“设计”视图中立即打开(请参见下图)。在表设计视图中打开了同一解决方案中的其他视图(在这里我可以直观地看到表适配器)。
我已经在此处进行了检查,但是当我尝试使用XML Schema Designer打开它时,仍然可以获得设计视图。如何打开xsd文件以再次实际看到表适配器?
我的网址看起来像这样:
www.example.com/historical+locations/london
和
www.example.com/special/london
我想看看URL是否包含某种格式.下面的表达式适用于出现special
,但+
历史位置的符号似乎搞乱了该字符串上的匹配.我尝试了以下表达式,它们都没有匹配......我似乎无法匹配包含+
字符的字符串
Dim urlMatch As Match = Regex.Match("/historical+locations/london",
"(^/special|^/\bhistorical+locations\b)/[a-zA-Z]",
RegexOptions.IgnoreCase)
Dim urlMatch As Match = Regex.Match("/historical+locations/london",
"(^/special|^/historical+locations)/[a-zA-Z]",
RegexOptions.IgnoreCase)
Dim urlMatch As Match = Regex.Match("/historical+locations/london",
"(^/special|^/historical+locations$)/[a-zA-Z]",
RegexOptions.IgnoreCase)
Run Code Online (Sandbox Code Playgroud)